2019-03-07 20:31:55 +00:00
|
|
|
/* eslint-env node */
|
2020-04-27 18:58:30 +00:00
|
|
|
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
|
2019-03-07 20:31:55 +00:00
|
|
|
const path = require( 'path' );
|
2019-02-19 13:09:52 +00:00
|
|
|
|
2019-03-07 20:31:55 +00:00
|
|
|
const PUBLIC_PATH = '/w/extensions/Popups';
|
2017-05-08 18:50:59 +00:00
|
|
|
|
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';
|
|
|
|
|
2019-03-07 20:31:55 +00:00
|
|
|
module.exports = ( env, argv ) => ( {
|
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.
|
2019-03-07 20:31:55 +00:00
|
|
|
bail: argv.mode === 'production',
|
2018-10-05 17:15:43 +00:00
|
|
|
|
|
|
|
// Specify that all paths are relative the Webpack configuration directory not the current
|
|
|
|
// working directory.
|
|
|
|
context: __dirname,
|
|
|
|
|
|
|
|
entry: { index: './src' },
|
|
|
|
|
2019-03-07 20:31:55 +00:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
redux: path.resolve(
|
|
|
|
__dirname,
|
|
|
|
argv.mode === 'production' ?
|
|
|
|
'node_modules/redux/dist/redux.min.js' :
|
|
|
|
'node_modules/redux/dist/redux.js'
|
|
|
|
),
|
|
|
|
'redux-thunk': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
argv.mode === 'production' ?
|
|
|
|
'node_modules/redux-thunk/dist/redux-thunk.min.js' :
|
|
|
|
'node_modules/redux-thunk/dist/redux-thunk.js'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [ {
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
// Beware of https://github.com/babel/babel-loader/issues/690. Changes to browsers require
|
|
|
|
// manual invalidation.
|
|
|
|
cacheDirectory: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
test: /\.svg$/,
|
|
|
|
loader: 'svg-inline-loader',
|
|
|
|
options: {
|
|
|
|
removeSVGTagAttrs: false // Keep width and height attributes.
|
|
|
|
}
|
|
|
|
} ]
|
|
|
|
},
|
2018-10-05 17:15:43 +00:00
|
|
|
optimization: {
|
|
|
|
// Don't produce production output when a build error occurs.
|
2019-03-07 20:31:55 +00:00
|
|
|
noEmitOnErrors: argv.mode === 'production',
|
2019-01-04 16:51:04 +00:00
|
|
|
|
|
|
|
// 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: {
|
2019-03-07 20:31:55 +00:00
|
|
|
// Specify the destination of all build products.
|
2018-10-05 17:15:43 +00:00
|
|
|
path: distDir,
|
2017-01-26 21:31:41 +00:00
|
|
|
|
2019-03-07 20:31:55 +00:00
|
|
|
// Store outputs per module in files named after the modules. For the JavaScript entry
|
|
|
|
// itself, append .js to each ResourceLoader module entry name. This value is tightly
|
|
|
|
// coupled to sourceMapFilename.
|
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.
|
2019-03-07 20:31:55 +00:00
|
|
|
sourceMapFilename: `[file]${srcMapExt}`,
|
|
|
|
|
|
|
|
devtoolModuleFilenameTemplate: `${PUBLIC_PATH}/[resource-path]`
|
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-03-07 20:31:55 +00:00
|
|
|
// Delete the output directory on each build.
|
2020-04-27 18:58:30 +00:00
|
|
|
new CleanWebpackPlugin( {
|
2020-06-22 21:49:14 +00:00
|
|
|
cleanOnceBeforeBuildPatterns: [ '**/*', '!.eslintrc.json' ]
|
2020-04-27 18:58:30 +00:00
|
|
|
} )
|
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.
|
2019-03-07 20:31:55 +00:00
|
|
|
hints: argv.mode === 'production' ? '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.
|
2021-03-09 17:21:48 +00:00
|
|
|
maxAssetSize: 43.3 * 1024,
|
|
|
|
maxEntrypointSize: 43.3 * 1024,
|
2018-10-05 17:15:43 +00:00
|
|
|
|
|
|
|
// The default filter excludes map files but we rename ours.
|
|
|
|
assetFilter: ( filename ) => !filename.endsWith( srcMapExt )
|
|
|
|
}
|
2019-03-07 20:31:55 +00:00
|
|
|
} );
|