I have a webpack.config.js file here. I’m trying to modify or overwrite the writeOutput
method of the webpack-bundle-tracker
app (saved as BundleTracker
) so that when the webpack-stats-prod.json
file is created it creates this (‘no path’):
{
"status": "done",
"assets": {
"78d4aa4961e00276aa1fe5487f7fcae4.eot": {
"name": "78d4aa4961e00276aa1fe5487f7fcae4.eot",
"path": "no path"
},
instead of this (absolute path):
{
"status": "done",
"assets": {
"78d4aa4961e00276aa1fe5487f7fcae4.eot": {
"name": "78d4aa4961e00276aa1fe5487f7fcae4.eot",
"path": "/Users/name/static/webpack/bundles/prod/78d4aa4961e00276aa1fe5487f7fcae4.eot"
},
I’m trying to do this by copying the webpack-bundle-tracker
app into a new variable (NoPathBundleTracker
) and then overwriting the writeOutput
method.
So far I’m getting this error: TypeError: Class constructor BundleTrackerPlugin cannot be invoked without 'new'
but I’m wondering if this is the best way to achieve my custom output.
const path = require('path');
const webpack = require('webpack');
const BundleTracker = require('webpack-bundle-tracker');
const config = require('./webpack.base.config.js');
var NoPathBundleTracker = function(options) {
BundleTracker.call(this, options);
};
// Edit webpack-bundle-tracker to not show path
NoPathBundleTracker.prototype = Object.create(BundleTracker.prototype);
NoPathBundleTracker.prototype.writeOutput = function (compiler, contents) {
var chunks = contents['chunks'];
if (chunks) {
for (var chunk in chunks ) {
var chunkArray = chunks[chunk];
var i;
for (i = 0; i < chunkArray.length; ++i) {
var chunkObject = chunkArray[i];
for ( var chunkinfo in chunkObject ) {
chunkObject['path'] = 'no path';
}
}
}
}
BundleTracker.prototype.writeOutput.call(this, compiler, contents);
};
config.output.path = path.resolve('./bundles/prod');
config.plugins = config.plugins.concat([
new NoPathBundleTracker({
filename: './webpack-stats-prod.json'
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}}),
]);
module.exports = config;