-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathwebpack.config.js
More file actions
111 lines (108 loc) · 2.75 KB
/
webpack.config.js
File metadata and controls
111 lines (108 loc) · 2.75 KB
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
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const path = require( 'path' );
const isProduction = process.env.NODE_ENV === 'production';
const MiniCSSExtractPlugin = require( 'mini-css-extract-plugin' );
const CopyPlugin = require( 'copy-webpack-plugin' );
const updatedConfig = {
...defaultConfig,
entry: {
...defaultConfig.entry(),
// Add your custom entries while preserving the automatic block detection
index : './src/index',
block : './src/block.js',
editor : './src/editor/index.js',
store : './src/data/store.js',
icons : './src/icons/index.js',
print : './src/assets/less/print.less',
frontend : './src/assets/less/frontend.less',
},
output: {
path: path.resolve( __dirname, 'assets/build' ),
assetModuleFilename: 'images/[name][ext]',
},
module: {
...defaultConfig.module,
rules: [
...defaultConfig.module.rules.filter(
rule => {
// Filter out the default image/asset rules
if (!rule.test) return true;
const testString = rule.test.toString();
return !testString.match(/jpg|jpeg|png|gif|svg|bmp|ico/i);
}
),
{
test: /\.less$/,
use: [
MiniCSSExtractPlugin.loader,
'css-loader',
'less-loader',
],
},
{
test: /\.(jpg|jpeg|png|gif|bmp|ico)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[name][ext]'
}
},
{
test: /\.svg$/i,
type: 'asset/resource',
generator: {
filename: (pathData) => {
// Check if SVG is from fonts directory
if (pathData.filename.includes('assets/fonts')) {
return 'fonts/[name][ext]';
}
return 'images/[name][ext]';
}
}
},
{
test: /\.(woff|woff2|ttf|eot)$/i,
type: 'asset/resource',
generator: {
filename: 'fonts/[name][ext]'
}
},
],
},
plugins: [
...defaultConfig.plugins,
new CopyPlugin( {
patterns: [
{
from: 'src/blocks/helpers',
to: 'blocks/helpers',
},
{
from: 'src/blocks/QuickSearch/templates',
to: 'blocks/QuickSearch/templates',
},
],
} ),
new MiniCSSExtractPlugin( {
filename: '[name].css',
chunkFilename: '[id].css',
} ),
],
};
if ( ! isProduction ) {
updatedConfig.devServer = {
devMiddleware: {
writeToDisk: true,
},
allowedHosts: 'all',
host: 'wedocs.test',
port: 8886,
proxy: {
'/assets/build': {
pathRewrite: {
'^/assets/build': '',
},
},
},
};
}
module.exports = updatedConfig;