-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
141 lines (132 loc) · 3.32 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
139
140
141
const path = require( 'path' );
// eslint-disable-next-line import/no-extraneous-dependencies
const jetpackWebpackConfig = require( '@automattic/jetpack-webpack-config/webpack' );
// eslint-disable-next-line import/no-extraneous-dependencies
const CopyPlugin = require( 'copy-webpack-plugin' );
const isProduction = process.env.NODE_ENV === 'production';
const cssGenPath = path.dirname(
path.dirname( require.resolve( 'jetpack-boost-critical-css-gen' ) )
);
const cssGenCopyPatterns = [
{
from: path.join( cssGenPath, 'dist/bundle.js' ),
to: 'critical-css-gen.js',
},
];
if ( ! isProduction ) {
cssGenCopyPatterns.push( {
from: path.join( cssGenPath, 'dist/bundle.js.map' ),
to: 'critical-css-gen.js.map',
} );
}
module.exports = [
/**
* The Boost plugin
*/
{
entry: {
index: './app/assets/src/js/index.tsx',
},
mode: jetpackWebpackConfig.mode,
devtool: jetpackWebpackConfig.devtool,
output: {
...jetpackWebpackConfig.output,
path: path.resolve( './app/assets/dist' ),
filename: 'jetpack-boost.js',
},
optimization: {
...jetpackWebpackConfig.optimization,
},
resolve: {
...jetpackWebpackConfig.resolve,
alias: {
...jetpackWebpackConfig.resolve.alias,
$lib: path.resolve( './app/assets/src/js/lib' ),
$features: path.resolve( './app/assets/src/js/features' ),
$layout: path.resolve( './app/assets/src/js/layout' ),
$svg: path.resolve( './app/assets/src/js/svg' ),
},
},
node: false,
plugins: [
...jetpackWebpackConfig.StandardPlugins( {
MiniCssExtractPlugin: {
filename: 'jetpack-boost.css',
},
DependencyExtractionPlugin: { injectPolyfill: true },
} ),
new CopyPlugin( { patterns: cssGenCopyPatterns } ),
],
module: {
strictExportPresence: true,
rules: [
// Transpile JavaScript
jetpackWebpackConfig.TranspileRule( {
exclude: /node_modules\//,
} ),
// Transpile @automattic/jetpack-* in node_modules too.
jetpackWebpackConfig.TranspileRule( {
includeNodeModules: [ '@automattic/jetpack-' ],
} ),
// Handle CSS.
jetpackWebpackConfig.CssRule( {
extensions: [ 'css', 'sass', 'scss' ],
extraLoaders: [ 'sass-loader' ],
} ),
// Handle images.
jetpackWebpackConfig.FileRule(),
],
},
externals: {
...jetpackWebpackConfig.externals,
jetpackConfig: JSON.stringify( {
consumer_slug: 'jetpack-boost',
} ),
},
},
/**
* Image Guide UI.
*/
{
entry: {
index: './app/modules/image-guide/src/index.ts',
},
mode: jetpackWebpackConfig.mode,
devtool: jetpackWebpackConfig.devtool,
output: {
path: path.resolve( './app/modules/image-guide/dist' ),
filename: 'guide.js',
},
optimization: {
...jetpackWebpackConfig.optimization,
},
resolve: {
...jetpackWebpackConfig.resolve,
alias: {
...jetpackWebpackConfig.resolve.alias,
$lib: path.resolve( './app/assets/src/js/lib' ),
},
},
node: false,
plugins: [
...jetpackWebpackConfig.StandardPlugins( {
DependencyExtractionPlugin: { injectPolyfill: true },
} ),
],
module: {
strictExportPresence: true,
rules: [
// Transpile JavaScript
jetpackWebpackConfig.TranspileRule( {
exclude: /node_modules\//,
} ),
],
},
externals: {
...jetpackWebpackConfig.externals,
jetpackConfig: JSON.stringify( {
consumer_slug: 'jetpack-boost',
} ),
},
},
];