This repository has been archived by the owner on Nov 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
webpack.config.js
executable file
·95 lines (91 loc) · 2.55 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
const path = require( 'path' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const IgnoreEmitPlugin = require( 'ignore-emit-webpack-plugin' );
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
const { defaultRequestToExternal, defaultRequestToHandle } = require( '@wordpress/dependency-extraction-webpack-plugin/lib/util' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
...defaultConfig,
entry: {
'./js/editor.blocks': './js/blocks/index.js',
'./js/admin.migration': './js/migration/index.js',
'./css/blocks.editor': './css/src/editor.scss',
},
output: {
path: path.resolve( __dirname ),
filename: '[name].js',
},
watch: false,
mode: isProduction ? 'production' : 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
},
},
{
test: /editor\.s?css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// Only allow hot module reloading in development.
hmr: process.env.NODE_ENV === 'development',
// Force reloading if hot module reloading does not work.
reloadAll: true,
},
},
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: [ require( 'autoprefixer' ) ],
},
},
{
loader: 'sass-loader',
},
],
},
],
},
plugins: [
new MiniCssExtractPlugin( {
filename: './css/blocks.editor.css',
} ),
// Copied from Gutenberg.
// MiniCSSExtractPlugin creates JavaScript assets for CSS that are
// obsolete and should be removed. Related webpack issue:
// https://github.com/webpack-contrib/mini-css-extract-plugin/issues/85
new IgnoreEmitPlugin( [ 'blocks.editor.js' ] ),
new DependencyExtractionWebpackPlugin( {
useDefaults: false,
requestToHandle: ( request ) => {
switch ( request ) {
case '@wordpress/dom-ready':
case '@wordpress/i18n':
case '@wordpress/server-side-render':
case '@wordpress/url':
return undefined;
default:
return defaultRequestToHandle( request );
}
},
requestToExternal: ( request ) => {
switch ( request ) {
case '@wordpress/dom-ready':
case '@wordpress/i18n':
case '@wordpress/server-side-render':
case '@wordpress/url':
return undefined;
default:
return defaultRequestToExternal( request );
}
},
} ),
],
};