4
4
const { DefinePlugin } = require ( 'webpack' ) ;
5
5
const CopyWebpackPlugin = require ( 'copy-webpack-plugin' ) ;
6
6
const postcss = require ( 'postcss' ) ;
7
- const { get, escapeRegExp } = require ( 'lodash' ) ;
7
+ const { get, escapeRegExp, compact } = require ( 'lodash' ) ;
8
8
const { basename, sep } = require ( 'path' ) ;
9
9
10
10
/**
11
11
* WordPress dependencies
12
12
*/
13
13
const CustomTemplatedPathPlugin = require ( '@wordpress/custom-templated-path-webpack-plugin' ) ;
14
14
const LibraryExportDefaultPlugin = require ( '@wordpress/library-export-default-webpack-plugin' ) ;
15
- const defaultConfig = require ( '@wordpress/scripts/config/ webpack.config ' ) ;
15
+ const DependencyExtractionWebpackPlugin = require ( '@wordpress/dependency-extraction- webpack-plugin ' ) ;
16
16
const { camelCaseDash } = require ( '@wordpress/scripts/utils' ) ;
17
17
18
18
/**
19
19
* Internal dependencies
20
20
*/
21
21
const { dependencies } = require ( './package' ) ;
22
22
23
+ const {
24
+ NODE_ENV : mode = 'development' ,
25
+ WP_DEVTOOL : devtool = ( mode === 'production' ? false : 'source-map' ) ,
26
+ } = process . env ;
27
+
23
28
const WORDPRESS_NAMESPACE = '@wordpress/' ;
24
29
25
30
const gutenbergPackages = Object . keys ( dependencies )
26
31
. filter ( ( packageName ) => packageName . startsWith ( WORDPRESS_NAMESPACE ) )
27
32
. map ( ( packageName ) => packageName . replace ( WORDPRESS_NAMESPACE , '' ) ) ;
28
33
29
34
module . exports = {
30
- ... defaultConfig ,
35
+ mode ,
31
36
entry : gutenbergPackages . reduce ( ( memo , packageName ) => {
32
37
const name = camelCaseDash ( packageName ) ;
33
38
memo [ name ] = `./packages/${ packageName } ` ;
@@ -39,8 +44,16 @@ module.exports = {
39
44
library : [ 'wp' , '[name]' ] ,
40
45
libraryTarget : 'this' ,
41
46
} ,
47
+ module : {
48
+ rules : compact ( [
49
+ mode !== 'production' && {
50
+ test : / \. j s $ / ,
51
+ use : require . resolve ( 'source-map-loader' ) ,
52
+ enforce : 'pre' ,
53
+ } ,
54
+ ] ) ,
55
+ } ,
42
56
plugins : [
43
- ...defaultConfig . plugins ,
44
57
new DefinePlugin ( {
45
58
// Inject the `GUTENBERG_PHASE` global, used for feature flagging.
46
59
// eslint-disable-next-line @wordpress/gutenberg-phase
@@ -82,7 +95,7 @@ module.exports = {
82
95
to : `./build/${ packageName } /` ,
83
96
flatten : true ,
84
97
transform : ( content ) => {
85
- if ( defaultConfig . mode === 'production' ) {
98
+ if ( mode === 'production' ) {
86
99
return postcss ( [
87
100
require ( 'cssnano' ) ( {
88
101
preset : [ 'default' , {
@@ -134,5 +147,7 @@ module.exports = {
134
147
} ,
135
148
} ,
136
149
] ) ,
150
+ new DependencyExtractionWebpackPlugin ( { injectPolyfill : true } ) ,
137
151
] ,
152
+ devtool,
138
153
} ;
0 commit comments