forked from folio-org/stripes-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.cli.prod.js
90 lines (81 loc) · 2.44 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Top level Webpack configuration for building static files for
// production deployment from the command line
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const postCssImport = require('postcss-import');
const autoprefixer = require('autoprefixer');
const postCssCustomProperties = require('postcss-custom-properties');
const postCssCalc = require('postcss-calc');
const postCssNesting = require('postcss-nesting');
const postCssCustomMedia = require('postcss-custom-media');
const postCssMediaMinMax = require('postcss-media-minmax');
const postCssColorFunction = require('postcss-color-function');
const base = require('./webpack.config.base');
const cli = require('./webpack.config.cli');
const prodConfig = Object.assign({}, base, cli, {
mode: 'production',
});
prodConfig.plugins = prodConfig.plugins.concat([
new MiniCssExtractPlugin({ filename: 'style.[contenthash].css', allChunks: true }),
new OptimizeCssAssetsPlugin(),
]);
prodConfig.module.rules.push({
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
localIdentName: '[local]---[hash:base64:5]',
modules: true,
importLoaders: 1,
},
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [
postCssImport(),
autoprefixer(),
postCssCustomProperties({
preserve: false
}),
postCssCalc(),
postCssNesting(),
postCssCustomMedia(),
postCssMediaMinMax(),
postCssColorFunction(),
],
},
},
],
});
prodConfig.module.rules.push(
{
test: /\.svg$/,
use: [
{ loader: 'file-loader?name=img/[path][name].[hash].[ext]' },
{
loader: 'svgo-loader',
options: {
plugins: [
{ removeTitle: true },
{ convertColors: { shorthex: false } },
{ convertPathData: false }
]
}
}
]
},
);
// Remove all data-test or data-test-* attributes
const babelLoaderConfig = prodConfig.module.rules.find(rule => rule.loader === 'babel-loader');
babelLoaderConfig.options.plugins = (babelLoaderConfig.options.plugins || []).concat([
[require.resolve('babel-plugin-remove-jsx-attributes'), {
patterns: ['^data-test.*$']
}]
]);
module.exports = prodConfig;