mediawiki-extensions-Popups/webpack.config.js

129 lines
3.9 KiB
JavaScript
Raw Normal View History

'use strict';
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const path = require( 'path' );
const PUBLIC_PATH = '/w/extensions/Popups';
const distDir = path.resolve( __dirname, 'resources/dist' );
// The extension used for source map files.
const srcMapExt = '.map.json';
module.exports = ( env, argv ) => ( {
// 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: argv.mode === 'production',
// Specify that all paths are relative the Webpack configuration directory not the current
// working directory.
context: __dirname,
entry: { index: './src' },
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.
}
}, {
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
} ]
},
optimization: {
// Don't produce production output when a build error occurs.
noEmitOnErrors: argv.mode === 'production',
// 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: {
// Specify the destination of all build products.
path: distDir,
// 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.
filename: '[name].js',
// Rename source map extensions. Per T173491 files with a .map extension cannot be served
// from prod.
sourceMapFilename: `[file]${srcMapExt}`,
devtoolModuleFilenameTemplate: `${PUBLIC_PATH}/[resource-path]`
},
// 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: [
// Delete the output directory on each build.
new CleanWebpackPlugin( {
cleanOnceBeforeBuildPatterns: [ '**/*', '!.eslintrc.json' ]
} )
],
performance: {
// Size violations for prod builds fail; development builds are unchecked.
hints: argv.mode === 'production' ? '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.
Generalize settings code (attempt 2) This reverts commit a6a65204c69399b8332c1894ee7ad7cece0fbeb5. to restore custom preview types. -- Changes since revert The previous patch accidentally removed the syncUserSettings changeListener. This has now been restored with several modifications: * We have a migrate script which rewrites existing localStorage settings to the new system * The existing save functions are generalized. The changes since this patch are captured in Ia73467799a9b535f7a3cf7268727c9fab7af0d7e -- More information A new REGISTER_SETTING action replaces the BOOT action for registering settings. This allows custom preview types to be associated with a setting. They do this by adding the enabled property to the module they provide to mw.popups.register Every time the new action is called, we refresh the settings dialog UI with the new settings. Previously the settings dialog was hardcoded, but now it is generated from the registered preview types by deriving associated messages and checking they exist, so by default custom types will not show up in the settings. Benefits: * This change empowers us to add a setting for Math previews to allow them to be enabled or disabled. * Allows us to separate references as its own module Additional notes: * The syncUserSettings.js changeListener is no longer needed as the logic for this is handled inside the "userSettings" change listener in response to the "settings" reducer which is responding to SETTINGS_CHANGE and REGISTER_SETTING actions. Upon merging: * https://www.mediawiki.org/wiki/Extension:Popups#Extensibility will be updated to detail how a setting can be registered. Bug: T334261 Bug: T326692 Change-Id: Ie17d622870511ac9730fc9fa525698fc3aa0d5b6
2023-10-19 21:12:09 +00:00
maxAssetSize: 47.8 * 1024,
maxEntrypointSize: 47.8 * 1024,
// The default filter excludes map files but we rename ours.
assetFilter: ( filename ) => !filename.endsWith( srcMapExt )
}
} );