2017-05-08 18:50:59 +00:00
|
|
|
/* global __dirname, process */
|
2018-03-15 16:30:11 +00:00
|
|
|
const path = require( 'path' ),
|
2017-05-08 17:06:54 +00:00
|
|
|
webpack = require( 'webpack' ),
|
2018-06-18 14:09:28 +00:00
|
|
|
CleanPlugin = require( 'clean-webpack-plugin' ),
|
2017-05-08 18:50:59 +00:00
|
|
|
PUBLIC_PATH = '/w/extensions/Popups',
|
2018-03-15 16:30:11 +00:00
|
|
|
isProduction = process.env.NODE_ENV === 'production';
|
|
|
|
|
2018-05-01 19:17:08 +00:00
|
|
|
const reduxPath = isProduction ?
|
2017-05-08 18:50:59 +00:00
|
|
|
'node_modules/redux/dist/redux.min.js' :
|
|
|
|
'node_modules/redux/dist/redux.js';
|
|
|
|
|
2018-05-01 19:17:08 +00:00
|
|
|
const reduxThunkPath = isProduction ?
|
2017-05-08 18:50:59 +00:00
|
|
|
'node_modules/redux-thunk/dist/redux-thunk.min.js' :
|
|
|
|
'node_modules/redux-thunk/dist/redux-thunk.js';
|
|
|
|
|
2018-05-01 19:17:08 +00:00
|
|
|
const conf = {
|
2017-01-26 21:31:41 +00:00
|
|
|
output: {
|
|
|
|
// The absolute path to the output directory.
|
2017-02-13 13:47:59 +00:00
|
|
|
path: path.resolve( __dirname, 'resources/dist' ),
|
2018-05-01 19:17:08 +00:00
|
|
|
devtoolModuleFilenameTemplate: `${PUBLIC_PATH}/[resource-path]`,
|
2017-01-26 21:31:41 +00:00
|
|
|
|
|
|
|
// Write each chunk (entries, here) to a file named after the entry, e.g.
|
|
|
|
// the "index" entry gets written to index.js.
|
2017-08-29 19:18:35 +00:00
|
|
|
filename: '[name].js',
|
|
|
|
// as we cannot serve .map files from production servers store map files
|
|
|
|
// with .json extension
|
2018-02-26 11:38:41 +00:00
|
|
|
sourceMapFilename: '[file].json'
|
2017-01-26 21:31:41 +00:00
|
|
|
},
|
2018-03-16 19:19:29 +00:00
|
|
|
entry: { index: './src' },
|
2018-03-16 17:56:40 +00:00
|
|
|
performance: {
|
|
|
|
hints: isProduction ? 'error' : false,
|
2018-03-27 19:43:43 +00:00
|
|
|
maxAssetSize: 40 * 1024,
|
|
|
|
maxEntrypointSize: 40 * 1024,
|
2018-03-16 17:56:40 +00:00
|
|
|
assetFilter: function ( filename ) {
|
|
|
|
// The default filter excludes map files but we rename ours to .filename.
|
|
|
|
return filename.endsWith( '.js' );
|
|
|
|
}
|
|
|
|
},
|
2017-03-03 10:14:37 +00:00
|
|
|
devtool: 'source-map',
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
2017-05-08 18:50:59 +00:00
|
|
|
redux: path.resolve( __dirname, reduxPath ),
|
|
|
|
'redux-thunk': path.resolve( __dirname, reduxThunkPath )
|
2017-03-03 10:14:37 +00:00
|
|
|
}
|
2017-03-03 10:24:45 +00:00
|
|
|
},
|
2018-03-07 19:53:09 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
2018-03-12 15:28:23 +00:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: { cacheDirectory: true }
|
|
|
|
}
|
|
|
|
},
|
2018-03-07 19:53:09 +00:00
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
|
|
|
loader: 'svg-inline-loader',
|
|
|
|
options: {
|
|
|
|
removeSVGTagAttrs: false // Keep width and height attributes.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2017-03-03 10:24:45 +00:00
|
|
|
plugins: [
|
2018-06-18 14:09:28 +00:00
|
|
|
new CleanPlugin( 'resources/dist', { verbose: false } ),
|
|
|
|
|
2017-03-03 10:24:45 +00:00
|
|
|
// 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
|
2017-10-11 21:19:39 +00:00
|
|
|
new webpack.NamedModulesPlugin()
|
2017-03-03 10:24:45 +00:00
|
|
|
]
|
2017-01-26 21:31:41 +00:00
|
|
|
};
|
2017-05-08 18:50:59 +00:00
|
|
|
|
|
|
|
// Production settings.
|
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.
|
2017-05-08 18:50:59 +00:00
|
|
|
// 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;
|