-
Notifications
You must be signed in to change notification settings - Fork 34
/
webpack.config.js
138 lines (136 loc) · 4.16 KB
/
webpack.config.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const defaultConfig = require("./node_modules/@wordpress/scripts/config/webpack.config"); // Require default Webpack config
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const TerserJSPlugin = require('terser-webpack-plugin');
const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
const RemovePlugin = require('remove-files-webpack-plugin');
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
const dashDash = require('@greenpeace/dashdash');
const mediaQueryAliases = {
'(max-width: 576px)': 'mobile-only',
'(min-width: 576px)': 'small-and-up',
'(min-width: 768px)': 'medium-and-up',
'(min-width: 992px)': 'large-and-up',
'(min-width: 1200px)': 'x-large-and-up',
'(min-width: 1600px)': 'xx-large-and-up',
};
module.exports = {
...defaultConfig,
entry: {
index: './assets/src/js/app.js',
style: './assets/src/scss/style.scss',
post: './assets/src/scss/post.scss',
editorStyle: './assets/src/scss/editorStyle.scss',
bootstrap: './assets/src/scss/bootstrap-build.scss',
"country-selector": './assets/src/scss/partials/country-selector.scss',
"navigation-bar": './assets/src/scss/partials/navigation-bar.scss',
"navigation-bar-dark": './assets/src/scss/partials/navigation-bar-dark.scss',
"navigation-bar-light": './assets/src/scss/partials/navigation-bar-light.scss',
"gravity-forms": './assets/src/scss/layout/_gravity-forms.scss',
new_identity_styles: './assets/src/scss/new-identity/style.scss',
media_archive: './assets/src/js/media_archive.js',
"lite-yt-embed": './node_modules/lite-youtube-embed/src/lite-yt-embed.js',
menu_editor: './assets/src/js/menu_editor.js',
},
output: {
filename: '[name].js',
path: __dirname + '/assets/build'
},
module: {
...defaultConfig.module,
rules: [
...defaultConfig.module.rules,
{
test: /\.(sass|scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
sourceMap: true,
}
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [
dashDash({ mediaQueryAliases, mediaQueryAtStart: false }),
require('autoprefixer'),
],
sourceMap: true,
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
}
}
]
},
{
test: /icons\/.*\.svg$/,
loader: 'svg-sprite-loader',
options: {
extract: true,
spriteFilename: '../../assets/build/sprite.symbol.svg',
runtimeCompat: true
}
},
]
},
plugins: [
...defaultConfig.plugins,
// extract css into dedicated file
new FixStyleOnlyEntriesPlugin(),
new MiniCssExtractPlugin({
chunkFilename: '[id].css',
ignoreOrder: false, // Enable to remove warnings about conflicting order
filename: './[name].min.css'
}),
new RemovePlugin({
/**
* After compilation removes all files in `dist/styles` folder,
* that have `.map` type.
*/
after: {
test: [
{
folder: 'assets/build/',
method: (filePath) => {
return [
'style.deps.json',
'index.asset.php',
'bootstrap.asset.php',
'style.asset.php',
].filter(item => {
return new RegExp(item, 'm').test(filePath);
}).length > 0;
}
}
]
}
}),
new SpriteLoaderPlugin({
plainSprite: true
}),
],
optimization: {
...defaultConfig.optimization,
minimizer: [
// enable the css minification plugin
new TerserJSPlugin({}),
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
sourceMap: true,
map: {
inline: false,
annotation: true,
}
}
})
]
}
};