mediawiki-extensions-Popups/webpack.config.js

95 lines
2.4 KiB
JavaScript
Raw Normal View History

/* global __dirname, process */
var path = require( 'path' ),
webpack = require( 'webpack' ),
PUBLIC_PATH = '/w/extensions/Popups',
isProduction = process.env.NODE_ENV === 'production',
reduxPath,
reduxThunkPath,
conf;
reduxPath = isProduction ?
'node_modules/redux/dist/redux.min.js' :
'node_modules/redux/dist/redux.js';
reduxThunkPath = isProduction ?
'node_modules/redux-thunk/dist/redux-thunk.min.js' :
'node_modules/redux-thunk/dist/redux-thunk.js';
conf = {
output: {
// The absolute path to the output directory.
path: path.resolve( __dirname, 'resources/dist' ),
devtoolModuleFilenameTemplate: PUBLIC_PATH + '/[resource-path]',
// Write each chunk (entries, here) to a file named after the entry, e.g.
// the "index" entry gets written to index.js.
filename: '[name].js',
// as we cannot serve .map files from production servers store map files
// with .json extension
sourceMapFilename: '[file].json'
},
Update: upgrade to Webpack 4 & improve output size Upgrade from Webpack v2.0.12 to v4.1.1. There have been many changes to Webpack... Noticeable in the bundle size is that a number of files are now inlined and generally minification is improved. Changes related to the upgrade include: - Remove unsupported UglifyJS options which link back to T188081. These appear to have been anticipatory but never acted on and it isn't clear whether they even worked or not. - Pass the -p plag for production optimizations; pass the -d flag since production doesn't support watching. - NamedModulesPlugin is now on by default but only in development mode so no change was made. - Webpack command line client now must be installed separated and appears in package.json as webpack-cli. https://github.com/webpack/webpack/releases/tag/v2.2.0 https://github.com/webpack/webpack/releases/tag/v2.2.1 https://github.com/webpack/webpack/releases/tag/v2.3.0 https://github.com/webpack/webpack/releases/tag/v2.3.1 https://github.com/webpack/webpack/releases/tag/v2.3.2 https://github.com/webpack/webpack/releases/tag/v2.3.3 https://github.com/webpack/webpack/releases/tag/v2.4.0 https://github.com/webpack/webpack/releases/tag/v2.4.1 https://github.com/webpack/webpack/releases/tag/v2.5.0 https://github.com/webpack/webpack/releases/tag/v2.5.1 https://github.com/webpack/webpack/releases/tag/v2.6.0 https://github.com/webpack/webpack/releases/tag/v2.6.1 https://github.com/webpack/webpack/releases/tag/v3.0.0 https://github.com/webpack/webpack/releases/tag/v3.1.0 https://github.com/webpack/webpack/releases/tag/v3.2.0 https://github.com/webpack/webpack/releases/tag/v3.3.0 https://github.com/webpack/webpack/releases/tag/v3.4.0 https://github.com/webpack/webpack/releases/tag/v3.4.1 https://github.com/webpack/webpack/releases/tag/v3.5.0 https://github.com/webpack/webpack/releases/tag/v3.5.1 https://github.com/webpack/webpack/releases/tag/v3.5.2 https://github.com/webpack/webpack/releases/tag/v3.5.3 https://github.com/webpack/webpack/releases/tag/v3.5.4 https://github.com/webpack/webpack/releases/tag/v3.5.5 https://github.com/webpack/webpack/releases/tag/v3.5.6 https://github.com/webpack/webpack/releases/tag/v3.6.0 https://github.com/webpack/webpack/releases/tag/v3.7.0 https://github.com/webpack/webpack/releases/tag/v3.7.1 https://github.com/webpack/webpack/releases/tag/v3.8.0 https://github.com/webpack/webpack/releases/tag/v3.8.1 https://github.com/webpack/webpack/releases/tag/v3.9.0 https://github.com/webpack/webpack/releases/tag/v3.9.1 https://github.com/webpack/webpack/releases/tag/v3.10.0 https://github.com/webpack/webpack/releases/tag/v3.11.0 https://github.com/webpack/webpack/releases/tag/v4.0.0 https://medium.com/webpack/webpack-4-released-today-6cdb994702d4 https://github.com/webpack/webpack/releases/tag/v4.0.1 https://github.com/webpack/webpack/releases/tag/v4.1.0 https://github.com/webpack/webpack/releases/tag/v4.1.1 Bug: T165036 Change-Id: Ic146e680d368fee7ee207b484460ce94f8bd7283
2018-03-16 19:19:29 +00:00
entry: { index: './src' },
performance: {
hints: isProduction ? 'error' : false,
maxAssetSize: 35.2 * 1024,
maxEntrypointSize: 35.2 * 1024,
assetFilter: function ( filename ) {
// The default filter excludes map files but we rename ours to .filename.
return filename.endsWith( '.js' );
}
},
devtool: 'source-map',
resolve: {
alias: {
redux: path.resolve( __dirname, reduxPath ),
'redux-thunk': path.resolve( __dirname, reduxThunkPath )
}
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: { cacheDirectory: true }
}
},
{
test: /\.svg$/,
loader: 'svg-inline-loader',
options: {
removeSVGTagAttrs: false // Keep width and height attributes.
}
}
]
},
plugins: [
// To generate identifiers that are preserved over builds, webpack supplies
// the NamedModulesPlugin (generates comments with file names on bundle)
// https://webpack.js.org/guides/caching/#deterministic-hashes
new webpack.NamedModulesPlugin()
]
};
// Production settings.
Update: upgrade to Webpack 4 & improve output size Upgrade from Webpack v2.0.12 to v4.1.1. There have been many changes to Webpack... Noticeable in the bundle size is that a number of files are now inlined and generally minification is improved. Changes related to the upgrade include: - Remove unsupported UglifyJS options which link back to T188081. These appear to have been anticipatory but never acted on and it isn't clear whether they even worked or not. - Pass the -p plag for production optimizations; pass the -d flag since production doesn't support watching. - NamedModulesPlugin is now on by default but only in development mode so no change was made. - Webpack command line client now must be installed separated and appears in package.json as webpack-cli. https://github.com/webpack/webpack/releases/tag/v2.2.0 https://github.com/webpack/webpack/releases/tag/v2.2.1 https://github.com/webpack/webpack/releases/tag/v2.3.0 https://github.com/webpack/webpack/releases/tag/v2.3.1 https://github.com/webpack/webpack/releases/tag/v2.3.2 https://github.com/webpack/webpack/releases/tag/v2.3.3 https://github.com/webpack/webpack/releases/tag/v2.4.0 https://github.com/webpack/webpack/releases/tag/v2.4.1 https://github.com/webpack/webpack/releases/tag/v2.5.0 https://github.com/webpack/webpack/releases/tag/v2.5.1 https://github.com/webpack/webpack/releases/tag/v2.6.0 https://github.com/webpack/webpack/releases/tag/v2.6.1 https://github.com/webpack/webpack/releases/tag/v3.0.0 https://github.com/webpack/webpack/releases/tag/v3.1.0 https://github.com/webpack/webpack/releases/tag/v3.2.0 https://github.com/webpack/webpack/releases/tag/v3.3.0 https://github.com/webpack/webpack/releases/tag/v3.4.0 https://github.com/webpack/webpack/releases/tag/v3.4.1 https://github.com/webpack/webpack/releases/tag/v3.5.0 https://github.com/webpack/webpack/releases/tag/v3.5.1 https://github.com/webpack/webpack/releases/tag/v3.5.2 https://github.com/webpack/webpack/releases/tag/v3.5.3 https://github.com/webpack/webpack/releases/tag/v3.5.4 https://github.com/webpack/webpack/releases/tag/v3.5.5 https://github.com/webpack/webpack/releases/tag/v3.5.6 https://github.com/webpack/webpack/releases/tag/v3.6.0 https://github.com/webpack/webpack/releases/tag/v3.7.0 https://github.com/webpack/webpack/releases/tag/v3.7.1 https://github.com/webpack/webpack/releases/tag/v3.8.0 https://github.com/webpack/webpack/releases/tag/v3.8.1 https://github.com/webpack/webpack/releases/tag/v3.9.0 https://github.com/webpack/webpack/releases/tag/v3.9.1 https://github.com/webpack/webpack/releases/tag/v3.10.0 https://github.com/webpack/webpack/releases/tag/v3.11.0 https://github.com/webpack/webpack/releases/tag/v4.0.0 https://medium.com/webpack/webpack-4-released-today-6cdb994702d4 https://github.com/webpack/webpack/releases/tag/v4.0.1 https://github.com/webpack/webpack/releases/tag/v4.1.0 https://github.com/webpack/webpack/releases/tag/v4.1.1 Bug: T165036 Change-Id: Ic146e680d368fee7ee207b484460ce94f8bd7283
2018-03-16 19:19:29 +00:00
// Define the global process.env.NODE_ENV so that libraries like redux and
// redux-thunk get development code trimmed.
// Enable minimize flags for webpack loaders and disable debug.
if ( isProduction ) {
conf.plugins = conf.plugins.concat( [
new webpack.LoaderOptionsPlugin( {
minimize: true,
debug: false
} ),
new webpack.DefinePlugin( {
'process.env': {
NODE_ENV: JSON.stringify( 'production' )
}
} )
] );
}
module.exports = conf;