mediawiki-extensions-Popups/webpack.config.js

122 lines
3.6 KiB
JavaScript
Raw Normal View History

/* global __dirname, process */
const
path = require( 'path' ),
CleanPlugin = require( 'clean-webpack-plugin' ),
PUBLIC_PATH = '/w/extensions/Popups',
isProduction = process.env.NODE_ENV === 'production';
const reduxPath = isProduction ?
'node_modules/redux/dist/redux.min.js' :
'node_modules/redux/dist/redux.js';
const reduxThunkPath = isProduction ?
'node_modules/redux-thunk/dist/redux-thunk.min.js' :
'node_modules/redux-thunk/dist/redux-thunk.js';
const distDir = path.resolve( __dirname, 'resources/dist' );
// The extension used for source map files.
const srcMapExt = '.map.json';
const conf = {
// Apply the rule of silence: https://wikipedia.org/wiki/Unix_philosophy.
stats: {
all: false,
// Output a timestamp when a build completes. Useful when watching files.
builtAt: true,
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.
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
},
output: {
// The absolute path to the output directory.
path: distDir,
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',
// Rename source map extensions. Per T173491 files with a .map extension cannot be served
// from prod.
sourceMapFilename: `[file]${srcMapExt}`
},
// 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: [
new CleanPlugin( distDir, { verbose: false } )
],
performance: {
// Size violations for prod builds fail; development builds are unchecked.
hints: isProduction ? 'error' : false,
// 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.
maxAssetSize: 40 * 1024,
maxEntrypointSize: 40 * 1024,
// The default filter excludes map files but we rename ours.
assetFilter: ( filename ) => !filename.endsWith( srcMapExt )
},
resolve: {
alias: {
redux: path.resolve( __dirname, reduxPath ),
'redux-thunk': path.resolve( __dirname, reduxThunkPath )
}
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
Switch from babel-preset-env to @babel/preset-env Replace: - babel-preset-env@1.6.0 with @babel/preset-env@7.2.0 - babel-register@6.24.1 with @babel/register@7.0.0 - babel-loader@7.1.4 with babel-loader@8.0.4 Add: - @babel/core@7.2.0 --- - babel-preset-env, @babel/preset-env babel-preset-env moved to @babel/preset-env in the Babel monorepo. This appears to have incremented the version from v1.6.0[0] to 7.x to match the rest of the Babel packages but appears to otherwise be undocumented.[1,3] [0] https://github.com/babel/babel-preset-env/blob/24b99ec/README.md [1] https://github.com/babel/babel/blob/efa571a/CHANGELOG.md - @babel/preset-env, @babel/register *Many* changes as identified by package [2] and summarized [3]. Node.js v6 or above now required. New dependency on @babel/core. Support for ES2018 and browserslist v4. `modules: false` is now the default for preset-env + babel-loader. The .babelrc has been updated. New babel-upgrade tool. babel.config.js can replace .babelrc. Popups doesn't seem to need it. TypeScript and JSX fragment support. [2] https://github.com/babel/babel/blob/efa571a/CHANGELOG.md [3] https://babeljs.io/blog/2018/08/27/7.0.0 - babel-loader Support for Babel 7.x. The following warning is printed when building but perhaps this is due to another dependency: (node:14559) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56 parseQuery() will be replaced with getOptions() in the next major version of loader-utils. https://github.com/webpack/loader-utils/issues/56#issuecomment-286117000 https://github.com/babel/babel-loader/releases/tag/v7.1.5 https://github.com/babel/babel-loader/releases/tag/v8.0.0-beta.0 https://github.com/babel/babel-loader/releases/tag/v8.0.0-beta.1 https://github.com/babel/babel-loader/releases/tag/v8.0.0-beta.2 https://github.com/babel/babel-loader/releases/tag/v8.0.0-beta.3 https://github.com/babel/babel-loader/releases/tag/v8.0.0-beta.4 (v8.0.0-beta.5 was erroneous.) https://github.com/babel/babel-loader/releases/tag/v8.0.0-beta.6 https://github.com/babel/babel-loader/releases/tag/v8.0.0 https://github.com/babel/babel-loader/releases/tag/v8.0.1 https://github.com/babel/babel-loader/releases/tag/v8.0.2 https://github.com/babel/babel-loader/releases/tag/v8.0.3 https://github.com/babel/babel-loader/releases/tag/v8.0.4 Bug: T197883 Change-Id: Ie3a5404630fde87ea7fe618a842950ed8c0c6494
2018-12-03 10:08:49 +00:00
options: {
cacheDirectory: true
}
}
},
{
test: /\.svg$/,
loader: 'svg-inline-loader',
options: {
removeSVGTagAttrs: false // Keep width and height attributes.
}
}
]
}
};
module.exports = conf;