Skip to content

Commit c12859d

Browse files
authored
Framework: Remove packages build from build, dev scripts (#15226)
* Framework: Omit Babel processing from Webpack configuration * Framework: Remove packages build from build, dev scripts * Build Tooling: Update Webpack config to operate on source files * Revert "Build Tooling: Update Webpack config to operate on source files" This reverts commit 8ca8c18. * Revert "Framework: Remove packages build from build, dev scripts" This reverts commit 0021e5c. * Scripts: Add flag `--no-babel` for excluding Babel processing * Framework: Exclude Babel processing by build script flag * Framework: Avoid extending default configuration in Webpack build
1 parent 2d541eb commit c12859d

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"shallow-equals": "1.0.0",
128128
"shallowequal": "1.1.0",
129129
"simple-git": "1.113.0",
130+
"source-map-loader": "0.2.4",
130131
"sprintf-js": "1.1.1",
131132
"stylelint-config-wordpress": "13.1.0",
132133
"uuid": "3.3.2",

webpack.config.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,35 @@
44
const { DefinePlugin } = require( 'webpack' );
55
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
66
const postcss = require( 'postcss' );
7-
const { get, escapeRegExp } = require( 'lodash' );
7+
const { get, escapeRegExp, compact } = require( 'lodash' );
88
const { basename, sep } = require( 'path' );
99

1010
/**
1111
* WordPress dependencies
1212
*/
1313
const CustomTemplatedPathPlugin = require( '@wordpress/custom-templated-path-webpack-plugin' );
1414
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' );
1616
const { camelCaseDash } = require( '@wordpress/scripts/utils' );
1717

1818
/**
1919
* Internal dependencies
2020
*/
2121
const { dependencies } = require( './package' );
2222

23+
const {
24+
NODE_ENV: mode = 'development',
25+
WP_DEVTOOL: devtool = ( mode === 'production' ? false : 'source-map' ),
26+
} = process.env;
27+
2328
const WORDPRESS_NAMESPACE = '@wordpress/';
2429

2530
const gutenbergPackages = Object.keys( dependencies )
2631
.filter( ( packageName ) => packageName.startsWith( WORDPRESS_NAMESPACE ) )
2732
.map( ( packageName ) => packageName.replace( WORDPRESS_NAMESPACE, '' ) );
2833

2934
module.exports = {
30-
...defaultConfig,
35+
mode,
3136
entry: gutenbergPackages.reduce( ( memo, packageName ) => {
3237
const name = camelCaseDash( packageName );
3338
memo[ name ] = `./packages/${ packageName }`;
@@ -39,8 +44,16 @@ module.exports = {
3944
library: [ 'wp', '[name]' ],
4045
libraryTarget: 'this',
4146
},
47+
module: {
48+
rules: compact( [
49+
mode !== 'production' && {
50+
test: /\.js$/,
51+
use: require.resolve( 'source-map-loader' ),
52+
enforce: 'pre',
53+
},
54+
] ),
55+
},
4256
plugins: [
43-
...defaultConfig.plugins,
4457
new DefinePlugin( {
4558
// Inject the `GUTENBERG_PHASE` global, used for feature flagging.
4659
// eslint-disable-next-line @wordpress/gutenberg-phase
@@ -82,7 +95,7 @@ module.exports = {
8295
to: `./build/${ packageName }/`,
8396
flatten: true,
8497
transform: ( content ) => {
85-
if ( defaultConfig.mode === 'production' ) {
98+
if ( mode === 'production' ) {
8699
return postcss( [
87100
require( 'cssnano' )( {
88101
preset: [ 'default', {
@@ -134,5 +147,7 @@ module.exports = {
134147
},
135148
},
136149
] ),
150+
new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ),
137151
],
152+
devtool,
138153
};

0 commit comments

Comments
 (0)