-
Notifications
You must be signed in to change notification settings - Fork 22
/
webpack.config.js
149 lines (143 loc) · 3.64 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
142
143
144
145
146
147
148
149
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const IS_DEV = process.env.NODE_ENV === 'development';
const extractCSS = new MiniCssExtractPlugin({
filename: 'css/[name].css',
});
const eslint = new ESLintPlugin({
cache: IS_DEV,
// This option makes ESLint automatically fix minor issues
fix: !IS_DEV,
});
const config = {
// Target is necessary in Webpack 5 to support IE11
target: ['web', 'es5'],
mode: IS_DEV ? 'development' : 'production',
entry: {
editor: './src/frontend/editor/webpackEntry.ts',
admin: './src/frontend/admin/webpackEntry.js',
'lazyload-vimeo': './src/frontend/lazyload-vimeo/webpackEntry.js',
'lazyload-youtube': './src/frontend/lazyload-youtube/webpackEntry.js',
},
module: {
rules: [
{
test: /\.(png|svg|jpg|gif)$/,
exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: {
name: 'media/[name].[ext]',
publicPath: '../',
},
},
],
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
],
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
happyPackMode: IS_DEV,
},
},
],
},
{
test: /\.s?css$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
'autoprefixer',
],
},
},
},
{
loader: 'sass-loader',
},
],
},
],
},
resolve: {
extensions: ['*', '.ts', '.tsx', '.js', '.scss'],
},
output: {
path: `${__dirname}/public/`,
filename: 'js/[name].js',
},
plugins: [
extractCSS,
eslint,
],
externals: {
// Manually import used WP packages because if we would use
// "@wordpress/dependency-extraction-webpack-plugin" instead,
// our use of "@wordpress/block-library" would throw an error
// because we're directly accessing internals that aren't
// exposed via the wp.blockLibrary API
'@wordpress/data': 'wp.data',
'@wordpress/i18n': 'wp.i18n',
'@wordpress/element': 'wp.element',
'@wordpress/compose': 'wp.compose',
'@wordpress/components': 'wp.components',
'@wordpress/hooks': 'wp.hooks',
'@wordpress/blocks': 'wp.blocks',
'@wordpress/block-editor': 'wp.blockEditor',
'@wordpress/block-library': 'wp.blockLibrary',
lodash: 'lodash',
},
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
splitChunks: {
cacheGroups: {
// Move shared code into a separate bundle
sharedProduction: {
name: 'lazyload-shared',
test: /\/shared(-utils)?\//,
chunks(chunk) {
// Exclude chunks
return chunk.name !== 'admin' && chunk.name !== 'editor';
},
priority: -10,
minSize: 0,
},
},
},
},
};
if (IS_DEV) {
config.devtool = 'eval-cheap-module-source-map';
}
module.exports = config;