-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.prod.js
74 lines (68 loc) · 1.95 KB
/
webpack.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
const { merge } = require('webpack-merge')
const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const postcssPresetEnv = require('postcss-preset-env')
const cssnano = require('cssnano')
const common = require('./webpack.common.js')
const config = require('./src/config')
const { graphConfig, uiConfig } = require('./src/graphing/config')
const featureToggles = config().production.featureToggles
const main = ['./src/site.js']
const scssVariables = []
Object.entries(graphConfig).forEach(function ([key, value]) {
scssVariables.push(`$${key}: ${value}px;`)
})
Object.entries(uiConfig).forEach(function ([key, value]) {
scssVariables.push(`$${key}: ${value}px;`)
})
Object.entries(featureToggles).forEach(function ([key, value]) {
scssVariables.push(`$${key}: ${value};`)
})
module.exports = merge(common, {
mode: 'production',
entry: { main },
performance: {
hints: false,
},
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { importLoaders: 1, modules: 'global', url: false },
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
postcssPresetEnv({ browsers: 'last 2 versions' }),
cssnano({
preset: ['default', { discardComments: { removeAll: true } }],
}),
],
},
},
},
{
loader: 'sass-loader',
options: {
additionalData: scssVariables.join('\n'),
},
},
],
},
],
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.ENVIRONMENT': JSON.stringify('production'),
}),
],
})