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

Extract reusable part of Webpack config and put in @wordpress/scripts #13814

Merged
merged 20 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0fbf5bc
New build-config package with webpack config.
griffbrad Dec 6, 2018
1c68315
Require new build-config package.
griffbrad Dec 6, 2018
5314e5b
Dynamically handle WP externals with a function.
griffbrad Dec 6, 2018
a519527
Use webpack config from build-config package.
griffbrad Dec 6, 2018
89af8f0
Require build-config package.
griffbrad Dec 6, 2018
942261f
Adjust file refs for WP packages.
griffbrad Dec 7, 2018
3c6cd93
Move main gutenberg entry definition and webpack copy plugin out of b…
griffbrad Dec 7, 2018
2c4f675
Add react-dev-utils for formatting webpack compiler messages.
griffbrad Dec 7, 2018
fff197d
Implement build script using webpack config from build-config.
griffbrad Dec 7, 2018
76e3848
Adjust output path so build goes to working directory.
griffbrad Dec 7, 2018
5f4eeda
Update package name to webpack-config
gziolo Feb 11, 2019
0d68bd4
Apply more tweaks to the way webpack config package is structured
gziolo Feb 12, 2019
8cdfd89
Update the way externals are handled
gziolo Feb 13, 2019
cc5cb36
Add default values for entry and output
gziolo Feb 18, 2019
3ce3e15
Move shared webpack config under @wordpress/scripts package
gziolo Feb 18, 2019
bb37c89
Improve the way how loaders are handled
gziolo Feb 19, 2019
4a6138e
Replace GUTENBERG with WP in webpack config env variables
nosolosw Feb 20, 2019
75551f8
Bring back feature flag to webpack config accidentally removed during…
gziolo Feb 20, 2019
8727c68
Add missing dev dependencies for the packages used in webpack config
gziolo Feb 20, 2019
3f54de4
Fix the list of excluded folders for babel-loader
gziolo Feb 20, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 52 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"@wordpress/npm-package-json-lint-config": "file:packages/npm-package-json-lint-config",
"@wordpress/postcss-themes": "file:packages/postcss-themes",
"@wordpress/scripts": "file:packages/scripts",
"babel-loader": "8.0.5",
"benchmark": "2.1.4",
"browserslist": "4.4.1",
"chalk": "2.4.1",
Expand Down Expand Up @@ -104,6 +103,7 @@
"node-watch": "0.6.0",
"pegjs": "0.10.0",
"phpegjs": "1.0.0-beta7",
"postcss": "7.0.13",
"react-dom": "16.6.3",
"react-test-renderer": "16.6.3",
"redux": "4.0.0",
Expand All @@ -113,13 +113,10 @@
"shallow-equal": "1.0.0",
"shallow-equals": "1.0.0",
"shallowequal": "1.1.0",
"source-map-loader": "0.2.3",
"sprintf-js": "1.1.1",
"stylelint-config-wordpress": "13.1.0",
"uuid": "3.3.2",
"webpack": "4.8.3",
"webpack-bundle-analyzer": "3.0.2",
"webpack-livereload-plugin": "2.1.1",
"webpack-rtl-plugin": "github:yoavf/webpack-rtl-plugin#develop"
},
"npmPackageJsonLintConfig": {
Expand Down
3 changes: 2 additions & 1 deletion packages/block-serialization-default-parser/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import path from 'path';
/**
* WordPress dependencies
*/
import { jsTester, phpTester } from '@wordpress/block-serialization-spec-parser';
// eslint-disable-next-line no-restricted-syntax
import { jsTester, phpTester } from '@wordpress/block-serialization-spec-parser/shared-tests';

/**
* Internal dependencies
Expand Down
10 changes: 8 additions & 2 deletions packages/block-serialization-spec-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## 2.1.0 (Unreleased)
## 3.0.0 (Unreleased)

- A `parser.php` file generated from the PEGJS grammar is now included.
## Breaking Change

- A `parser.js` file generated from the PEGJS grammar is now outputted in commonjs format.

## New Feature

- A `parser.php` file generated from the PEGJS grammar is now added upon installation.

## 2.0.2 (2018-12-12)

Expand Down
2 changes: 0 additions & 2 deletions packages/block-serialization-spec-parser/index.js

This file was deleted.

6 changes: 5 additions & 1 deletion packages/block-serialization-spec-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
"bugs": {
"url": "https://github.com/WordPress/gutenberg/issues"
},
"main": "parser.js",
"dependencies": {
"pegjs": "^0.10.0"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "concurrently \"npm run build:js\" \"npm run build:php\"",
"build:js": "pegjs --format umd -o ./parser.js ./grammar.pegjs",
"build:js": "pegjs --format commonjs -o ./parser.js ./grammar.pegjs",
"build:php": "node bin/create-php-parser.js"
}
}
3 changes: 2 additions & 1 deletion packages/block-serialization-spec-parser/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import path from 'path';
/**
* Internal dependencies
*/
import { jsTester, phpTester, parse } from '../';
import { parse } from '../';
import { jsTester, phpTester } from '../shared-tests';

describe( 'block-serialization-spec-parser-js', jsTester( parse ) );

Expand Down
109 changes: 109 additions & 0 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* External dependencies
*/
const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' );
const LiveReloadPlugin = require( 'webpack-livereload-plugin' );
const path = require( 'path' );

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

/**
* Converts @wordpress/* string request into request object.
*
* Note this isn't the same as camel case because of the
* way that numbers don't trigger the capitalized next letter.
*
* @example
* formatRequest( '@wordpress/api-fetch' );
* // { this: [ 'wp', 'apiFetch' ] }
* formatRequest( '@wordpress/i18n' );
* // { this: [ 'wp', 'i18n' ] }
*
* @param {string} request Request name from import statement.
* @return {Object} Request object formatted for further processing.
*/
const formatRequest = ( request ) => {
// '@wordpress/api-fetch' -> [ '@wordpress', 'api-fetch' ]
const [ , name ] = request.split( '/' );

// { this: [ 'wp', 'apiFetch' ] }
return {
this: [ 'wp', camelCaseDash( name ) ],
};
};

const wordpressExternals = ( context, request, callback ) => {
if ( /^@wordpress\//.test( request ) ) {
callback( null, formatRequest( request ), 'this' );
} else {
callback();
}
};

const externals = [
{
react: 'React',
'react-dom': 'ReactDOM',
moment: 'moment',
jquery: 'jQuery',
lodash: 'lodash',
'lodash-es': 'lodash',
},
wordpressExternals,
];

const isProduction = process.env.NODE_ENV === 'production';
const mode = isProduction ? 'production' : 'development';

const config = {
mode,
entry: {
index: path.resolve( process.cwd(), 'src', 'index.js' ),
},
output: {
filename: '[name].js',
path: path.resolve( process.cwd(), 'build' ),
},
externals,
resolve: {
oandregal marked this conversation as resolved.
Show resolved Hide resolved
alias: {
'lodash-es': 'lodash',
},
},
module: {
rules: [
{
test: /\.js$/,
use: require.resolve( 'source-map-loader' ),
enforce: 'pre',
},
{
test: /\.js$/,
exclude: /node_modules/,
use: require.resolve( 'babel-loader' ),
},
],
},
plugins: [
// WP_BUNDLE_ANALYZER global variable enables utility that represents bundle content
// as convenient interactive zoomable treemap.
process.env.WP_BUNDLE_ANALYZER && new BundleAnalyzerPlugin(),
// WP_LIVE_RELOAD_PORT global variable changes port on which live reload works
// when running watch mode.
! isProduction && new LiveReloadPlugin( { port: process.env.WP_LIVE_RELOAD_PORT || 35729 } ),
].filter( Boolean ),
stats: {
children: false,
},
};

if ( ! isProduction ) {
// WP_DEVTOOL global variable controls how source maps are generated.
// See: https://webpack.js.org/configuration/devtool/#devtool.
config.devtool = process.env.WP_DEVTOOL || 'source-map';
}

module.exports = config;
6 changes: 5 additions & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@wordpress/eslint-plugin": "file:../eslint-plugin",
"@wordpress/jest-preset-default": "file:../jest-preset-default",
"@wordpress/npm-package-json-lint-config": "file:../npm-package-json-lint-config",
"babel-loader": "^8.0.5",
"chalk": "^2.4.1",
"check-node-version": "^3.1.1",
"cross-spawn": "^5.1.0",
Expand All @@ -45,10 +46,13 @@
"puppeteer": "1.6.1",
"read-pkg-up": "^1.0.1",
"resolve-bin": "^0.4.0",
"source-map-loader": "^0.2.4",
"stylelint": "^9.10.1",
"stylelint-config-wordpress": "^13.1.0",
"webpack": "4.8.3",
"webpack-cli": "^3.1.2"
"webpack-bundle-analyzer": "^3.0.3",
"webpack-cli": "^3.1.2",
"webpack-livereload-plugin": "^2.2.0"
},
"publishConfig": {
"access": "public"
Expand Down
1 change: 0 additions & 1 deletion packages/scripts/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ if ( hasWebpackConfig ) {
console.log( 'Webpack config file is missing.' );
process.exit( 1 );
}

4 changes: 4 additions & 0 deletions packages/scripts/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ const {
const {
hasPackageProp,
} = require( './package' );
const {
camelCaseDash,
} = require( './string' );

module.exports = {
camelCaseDash,
fromConfigRoot,
getCliArg,
getCliArgs,
Expand Down
Loading