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' ),
|
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';
|
|
|
|
|
|
|
|
let reduxPath,
|
2017-05-08 18:50:59 +00:00
|
|
|
reduxThunkPath,
|
|
|
|
conf;
|
2017-01-26 21:31:41 +00:00
|
|
|
|
2017-05-08 18:50:59 +00:00
|
|
|
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 = {
|
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-03-20 19:06:49 +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-20 19:06:49 +00:00
|
|
|
maxAssetSize: 35.3 * 1024,
|
|
|
|
maxEntrypointSize: 35.3 * 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: [
|
|
|
|
// 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;
|