-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
89 lines (85 loc) · 2.21 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
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const defaultConfig = require('@wordpress/scripts/config/webpack.config.js');
const { hasCssnanoConfig, hasPostCSSConfig } = require('@wordpress/scripts/utils');
const postcssPlugins = require('@wordpress/postcss-plugins-preset');
const isProduction = defaultConfig.mode === 'production';
// Prepare CSS loaders
const cssLoaders = [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: require.resolve('css-loader'),
options: {
sourceMap: !isProduction,
modules: {
auto: true,
},
},
},
{
loader: require.resolve('postcss-loader'),
options: {
// Provide a fallback configuration if there's not
// one explicitly available in the project.
...(!hasPostCSSConfig() && {
postcssOptions: {
ident: 'postcss',
sourceMap: !isProduction,
plugins: isProduction
? [
...postcssPlugins,
require('cssnano')({
// Provide a fallback configuration if there's not
// one explicitly available in the project.
...(!hasCssnanoConfig() && {
preset: [
'default',
{
discardComments: {
removeAll: true,
},
},
],
}),
}),
]
: postcssPlugins,
},
}),
},
},
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: !isProduction,
},
},
];
module.exports = {
...defaultConfig,
entry: {
editor: { import: './blocks/index', filename: './js/blocks.editor.js' },
frontend: { import: './blocks/frontend', filename: './js/blocks.js' }
},
output: {
filename: '[name].js',
path: path.resolve(process.cwd(), 'assets'),
},
module: {
...defaultConfig.module,
rules: [
defaultConfig.module.rules[0],
{
test: /\.(sc|sa)ss$/,
use: [
...cssLoaders,
],
},
],
},
plugins: [
new MiniCssExtractPlugin({ filename: 'css/[name].css' }),
],
};