2017-05-08 18:50:59 +00:00
|
|
|
/* global __dirname, process */
|
2019-01-04 16:51:04 +00:00
|
|
|
const
|
|
|
|
path = require( 'path' ),
|
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-10-05 17:15:43 +00:00
|
|
|
const distDir = path.resolve( __dirname, 'resources/dist' );
|
|
|
|
|
|
|
|
// The extension used for source map files.
|
|
|
|
const srcMapExt = '.map.json';
|
|
|
|
|
2018-05-01 19:17:08 +00:00
|
|
|
const conf = {
|
2018-10-05 17:15:43 +00:00
|
|
|
// Apply the rule of silence: https://wikipedia.org/wiki/Unix_philosophy.
|
|
|
|
stats: {
|
|
|
|
all: false,
|
2019-01-14 21:16:22 +00:00
|
|
|
// Output a timestamp when a build completes. Useful when watching files.
|
|
|
|
builtAt: true,
|
2018-10-05 17:15:43 +00:00
|
|
|
errors: true,
|
|
|
|
warnings: true
|
|
|
|
},
|
|
|
|
|
|
|
|
// Fail on the first build error instead of tolerating it for prod builds. This seems to
|
|
|
|
// correspond to optimization.noEmitOnErrors.
|
|
|
|
bail: isProduction,
|
|
|
|
|
|
|
|
// Specify that all paths are relative the Webpack configuration directory not the current
|
|
|
|
// working directory.
|
|
|
|
context: __dirname,
|
|
|
|
|
|
|
|
entry: { index: './src' },
|
|
|
|
|
|
|
|
optimization: {
|
|
|
|
// Don't produce production output when a build error occurs.
|
2019-01-04 16:51:04 +00:00
|
|
|
noEmitOnErrors: isProduction,
|
|
|
|
|
|
|
|
// Use filenames instead of unstable numerical identifiers for file references. This
|
|
|
|
// increases the gzipped bundle size some but makes the build products easier to debug and
|
|
|
|
// appear deterministic. I.e., code changes will only alter the bundle they're packed in
|
|
|
|
// instead of shifting the identifiers in other bundles.
|
|
|
|
// https://webpack.js.org/guides/caching/#deterministic-hashes (namedModules replaces NamedModulesPlugin.)
|
|
|
|
namedModules: true
|
2018-10-05 17:15:43 +00:00
|
|
|
},
|
|
|
|
|
2017-01-26 21:31:41 +00:00
|
|
|
output: {
|
|
|
|
// The absolute path to the output directory.
|
2018-10-05 17:15:43 +00:00
|
|
|
path: distDir,
|
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',
|
2018-10-05 17:15:43 +00:00
|
|
|
|
|
|
|
// Rename source map extensions. Per T173491 files with a .map extension cannot be served
|
|
|
|
// from prod.
|
|
|
|
sourceMapFilename: `[file]${srcMapExt}`
|
2017-01-26 21:31:41 +00:00
|
|
|
},
|
2018-10-05 17:15:43 +00:00
|
|
|
|
|
|
|
// Accurate source maps at the expense of build time. The source map is intentionally exposed
|
|
|
|
// to users via sourceMapFilename for prod debugging. This goes against convention as source
|
|
|
|
// code is publicly distributed.
|
|
|
|
devtool: 'source-map',
|
|
|
|
|
|
|
|
plugins: [
|
2019-01-04 16:51:04 +00:00
|
|
|
new CleanPlugin( distDir, { verbose: false } )
|
2018-10-05 17:15:43 +00:00
|
|
|
],
|
|
|
|
|
2018-03-16 17:56:40 +00:00
|
|
|
performance: {
|
2018-10-05 17:15:43 +00:00
|
|
|
// Size violations for prod builds fail; development builds are unchecked.
|
2018-03-16 17:56:40 +00:00
|
|
|
hints: isProduction ? 'error' : false,
|
2018-10-05 17:15:43 +00:00
|
|
|
|
|
|
|
// Minified uncompressed size limits for chunks / assets and entrypoints. Keep these numbers
|
|
|
|
// up-to-date and rounded to the nearest 10th of a kibibyte so that code sizing costs are
|
|
|
|
// well understood. Related to bundlesize minified, gzipped compressed file size tests.
|
|
|
|
// Note: entrypoint size implicitly includes the mobile.startup.runtime entry.
|
2018-03-27 19:43:43 +00:00
|
|
|
maxAssetSize: 40 * 1024,
|
|
|
|
maxEntrypointSize: 40 * 1024,
|
2018-10-05 17:15:43 +00:00
|
|
|
|
|
|
|
// The default filter excludes map files but we rename ours.
|
|
|
|
assetFilter: ( filename ) => !filename.endsWith( srcMapExt )
|
2018-03-16 17:56:40 +00:00
|
|
|
},
|
2018-10-05 17:15:43 +00:00
|
|
|
|
2017-03-03 10:14:37 +00:00
|
|
|
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-10-05 17:15:43 +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',
|
2018-12-03 10:08:49 +00:00
|
|
|
options: {
|
|
|
|
cacheDirectory: true
|
|
|
|
}
|
2018-03-12 15:28:23 +00:00
|
|
|
}
|
|
|
|
},
|
2018-03-07 19:53:09 +00:00
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
|
|
|
loader: 'svg-inline-loader',
|
|
|
|
options: {
|
|
|
|
removeSVGTagAttrs: false // Keep width and height attributes.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2018-10-05 17:15:43 +00:00
|
|
|
}
|
2017-01-26 21:31:41 +00:00
|
|
|
};
|
2017-05-08 18:50:59 +00:00
|
|
|
|
|
|
|
module.exports = conf;
|