Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework: Remove packages build from build, dev scripts #15226

Merged
merged 8 commits into from
May 30, 2019
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"shallow-equals": "1.0.0",
"shallowequal": "1.1.0",
"simple-git": "1.113.0",
"source-map-loader": "0.2.4",
"sprintf-js": "1.1.1",
"stylelint-config-wordpress": "13.1.0",
"uuid": "3.3.2",
Expand Down
25 changes: 20 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,35 @@
const { DefinePlugin } = require( 'webpack' );
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
const postcss = require( 'postcss' );
const { get, escapeRegExp } = require( 'lodash' );
const { get, escapeRegExp, compact } = require( 'lodash' );
const { basename, sep } = require( 'path' );

/**
* WordPress dependencies
*/
const CustomTemplatedPathPlugin = require( '@wordpress/custom-templated-path-webpack-plugin' );
const LibraryExportDefaultPlugin = require( '@wordpress/library-export-default-webpack-plugin' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
const { camelCaseDash } = require( '@wordpress/scripts/utils' );

/**
* Internal dependencies
*/
const { dependencies } = require( './package' );

const {
NODE_ENV: mode = 'development',
WP_DEVTOOL: devtool = ( mode === 'production' ? false : 'source-map' ),
} = process.env;

const WORDPRESS_NAMESPACE = '@wordpress/';

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

module.exports = {
...defaultConfig,
mode,
entry: gutenbergPackages.reduce( ( memo, packageName ) => {
const name = camelCaseDash( packageName );
memo[ name ] = `./packages/${ packageName }`;
Expand All @@ -39,8 +44,16 @@ module.exports = {
library: [ 'wp', '[name]' ],
libraryTarget: 'this',
},
module: {
rules: compact( [
mode !== 'production' && {
test: /\.js$/,
use: require.resolve( 'source-map-loader' ),
enforce: 'pre',
},
] ),
},
plugins: [
...defaultConfig.plugins,
new DefinePlugin( {
// Inject the `GUTENBERG_PHASE` global, used for feature flagging.
// eslint-disable-next-line @wordpress/gutenberg-phase
Expand Down Expand Up @@ -82,7 +95,7 @@ module.exports = {
to: `./build/${ packageName }/`,
flatten: true,
transform: ( content ) => {
if ( defaultConfig.mode === 'production' ) {
if ( mode === 'production' ) {
return postcss( [
require( 'cssnano' )( {
preset: [ 'default', {
Expand Down Expand Up @@ -134,5 +147,7 @@ module.exports = {
},
},
] ),
new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two things that are removed by this change. I believe the webpack bundle analyzer and the live reload config. I'm not sure if people find these useful or not but I thought I'd mention.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two things that are removed by this change. I believe the webpack bundle analyzer and the live reload config. I'm not sure if people find these useful or not but I thought I'd mention.

Oof. Well, I can go conservative and leave the behavior unaffected, with the downsides of (a) more duplication and (b) more changes to package.json and package-lock.json or (b) just drop them. I've personally not made use of them (though in the former case, I have done bundle analysis by just calling webpack --stats directly).

Not sure yet how I want to proceed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally fine with just removing those as not much used but it could be done separately and I think we can move forward here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally fine with just removing those as not much used but it could be done separately and I think we can move forward here.

I'll commit to reintroducing it if anyone mentions it.

],
devtool,
};