This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
forked from folio-org/stripes-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.cli.prod.js
72 lines (62 loc) · 2.24 KB
/
webpack.config.cli.prod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Top level Webpack configuration for building static files for
// production deployment from the command line
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { EsbuildPlugin } = require('esbuild-loader');
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
const buildBaseConfig = require('./webpack.config.base');
const cli = require('./webpack.config.cli');
const esbuildLoaderRule = require('./webpack/esbuild-loader-rule');
const { getModulesPaths, getStripesModulesPaths, getTranspiledModules } = require('./webpack/module-paths');
const buildConfig = (stripesConfig) => {
const modulePaths = getModulesPaths(stripesConfig.modules);
const stripesModulePaths = getStripesModulesPaths();
const allModulePaths = [...stripesModulePaths, ...modulePaths];
const base = buildBaseConfig(allModulePaths);
const prodConfig = Object.assign({}, base, cli, {
mode: 'production',
devtool: 'source-map',
infrastructureLogging: {
appendOnly: true,
level: 'warn',
},
});
const transpiledModules = getTranspiledModules(allModulePaths);
const transpiledModulesRegex = new RegExp(transpiledModules.join('|'));
const smp = new SpeedMeasurePlugin();
prodConfig.plugins = prodConfig.plugins.concat([
new webpack.ProvidePlugin({
process: 'process/browser.js',
}),
]);
prodConfig.optimization = {
mangleWasmImports: false,
minimizer: [
new EsbuildPlugin({
css: true,
}),
],
splitChunks: {
// Do not process stripes chunk
chunks: (chunk) => {
return chunk.name !== 'stripes';
},
cacheGroups: {
// this cache group will be omitted by minimizer
stripes: {
// only include already transpiled modules
test: (module) => transpiledModulesRegex.test(module.resource),
name: 'stripes',
chunks: 'all'
},
},
},
}
prodConfig.module.rules.push(esbuildLoaderRule(allModulePaths));
const webpackConfig = smp.wrap({ plugins: prodConfig.plugins });
webpackConfig.plugins.push(
new MiniCssExtractPlugin({ filename: 'style.[contenthash].css' })
);
return { ...prodConfig, ...webpackConfig };
};
module.exports = buildConfig;