diff --git a/docs/manifest.json b/docs/manifest.json index 675c7034e52a1..b9d9523fe5c21 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -821,6 +821,12 @@ "markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/viewport/README.md", "parent": "packages" }, + { + "title": "@wordpress/webpack-config", + "slug": "packages-webpack-config", + "markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/webpack-config/README.md", + "parent": "packages" + }, { "title": "@wordpress/wordcount", "slug": "packages-wordcount", diff --git a/package-lock.json b/package-lock.json index f9f61b43e4c61..4e337d5bb945a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2380,10 +2380,6 @@ "version": "file:packages/browserslist-config", "dev": true }, - "@wordpress/build-config": { - "version": "file:packages/build-config", - "dev": true - }, "@wordpress/components": { "version": "file:packages/components", "requires": { @@ -2830,6 +2826,14 @@ "lodash": "^4.17.10" } }, + "@wordpress/webpack-config": { + "version": "file:packages/webpack-config", + "dev": true, + "requires": { + "webpack-bundle-analyzer": "^3.0.3", + "webpack-livereload-plugin": "^2.2.0" + } + }, "@wordpress/wordcount": { "version": "file:packages/wordcount", "requires": { @@ -14889,6 +14893,34 @@ "integrity": "sha512-2qHaIQr2VLRFoxe2nASzsV6ef4yOOH+Fi9FBOVH6cqeSgUnoyySPZkxzLuzd+RYOQTRpROA0ztTMqxROKSb/nA==", "dev": true }, + "portfinder": { + "version": "1.0.20", + "resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.20.tgz", + "integrity": "sha512-Yxe4mTyDzTd59PZJY4ojZR8F+E5e97iq2ZOHPz3HDgSvYC5siNad2tLooQ5y5QHyQhc3xVqvyk/eNA3wuoa7Sw==", + "dev": true, + "requires": { + "async": "^1.5.2", + "debug": "^2.2.0", + "mkdirp": "0.5.x" + }, + "dependencies": { + "async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=", + "dev": true + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + } + } + }, "posix-character-classes": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz", @@ -20568,9 +20600,9 @@ } }, "webpack-bundle-analyzer": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/webpack-bundle-analyzer/-/webpack-bundle-analyzer-3.0.2.tgz", - "integrity": "sha512-cZG4wSQtKrSpk5RJ33dxiaAyo8bP0V+JvycAyIDFEiDIhw4LHhhVKhn40YT1w6TR9E4scHA00LnIoBtTA13Mow==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/webpack-bundle-analyzer/-/webpack-bundle-analyzer-3.0.3.tgz", + "integrity": "sha512-naLWiRfmtH4UJgtUktRTLw6FdoZJ2RvCR9ePbwM9aRMsS/KjFerkPZG9epEvXRAw5d5oPdrs9+3p+afNjxW8Xw==", "dev": true, "requires": { "acorn": "^5.7.3", @@ -20594,9 +20626,9 @@ "dev": true }, "commander": { - "version": "2.18.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.18.0.tgz", - "integrity": "sha512-6CYPa+JP2ftfRU2qkDK+UTVeQYosOg/2GbcjIcKPHfinyOLPVGXu/ovN86RP49Re5ndJK1N0kuiidFFuepc4ZQ==", + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz", + "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==", "dev": true } } @@ -20800,11 +20832,12 @@ } }, "webpack-livereload-plugin": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/webpack-livereload-plugin/-/webpack-livereload-plugin-2.1.1.tgz", - "integrity": "sha512-W7Q55QbPvVJotpIZSjjwzmqQ22333ExYxWM3WFlHKkbPStQqVRSmJkjntUqXF9jtpdeXi8r8HLkA1RVnAP0SQA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/webpack-livereload-plugin/-/webpack-livereload-plugin-2.2.0.tgz", + "integrity": "sha512-sx9xA5mHoNOUgLQI0PmXT3KV9ecsVmUaTgr+fsoL69qAOHw/7VzkL1+ZMDQ8n0dPbWounswK6cBRSgMod7Nhgg==", "dev": true, "requires": { + "portfinder": "^1.0.17", "tiny-lr": "^1.1.1" } }, diff --git a/package.json b/package.json index 7e8787c221771..a50e84b098f0b 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,6 @@ "@wordpress/babel-plugin-makepot": "file:packages/babel-plugin-makepot", "@wordpress/babel-preset-default": "file:packages/babel-preset-default", "@wordpress/browserslist-config": "file:packages/browserslist-config", - "@wordpress/build-config": "file:packages/build-config", "@wordpress/custom-templated-path-webpack-plugin": "file:packages/custom-templated-path-webpack-plugin", "@wordpress/e2e-test-utils": "file:packages/e2e-test-utils", "@wordpress/e2e-tests": "file:packages/e2e-tests", @@ -72,6 +71,7 @@ "@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", + "@wordpress/webpack-config": "file:packages/webpack-config", "babel-loader": "8.0.0", "benchmark": "2.1.4", "browserslist": "4.4.1", @@ -114,8 +114,6 @@ "source-map-loader": "0.2.3", "stylelint-config-wordpress": "13.1.0", "uuid": "3.3.2", - "webpack-bundle-analyzer": "3.0.2", - "webpack-livereload-plugin": "2.1.1", "webpack-rtl-plugin": "github:yoavf/webpack-rtl-plugin#develop" }, "npmPackageJsonLintConfig": { diff --git a/packages/build-config/README.md b/packages/build-config/README.md deleted file mode 100644 index 8531700ebf4af..0000000000000 --- a/packages/build-config/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Build Config - diff --git a/packages/build-config/index.js b/packages/build-config/index.js deleted file mode 100644 index 56b88a5e9c8c0..0000000000000 --- a/packages/build-config/index.js +++ /dev/null @@ -1,6 +0,0 @@ -const webpackConfig = require( './config/webpack.config.js' ); - -module.exports = { - webpackConfig, -}; - diff --git a/packages/build-config/package.json b/packages/build-config/package.json deleted file mode 100644 index bad5afa7be0e3..0000000000000 --- a/packages/build-config/package.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "name": "@wordpress/build-config", - "version": "1.0.0", - "description": "WordPress JavaScript build configuration.", - "author": "The WordPress Contributors", - "license": "GPL-2.0-or-later", - "keywords": [ - "wordpress", - "build", - "config" - ], - "homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/build-config/README.md", - "repository": { - "type": "git", - "url": "https://github.com/WordPress/gutenberg.git" - }, - "bugs": { - "url": "https://github.com/WordPress/gutenberg/issues" - }, - "engines": { - "node": ">=8", - "npm": ">=6.0.0" - }, - "files": [ - "build", - "build-module" - ], - "main": "build/index.js", - "module": "build-module/index.js", - "dependencies": { - "@babel/core": "7.0.0", - "@babel/runtime-corejs2": "7.0.0", - "@wordpress/babel-plugin-import-jsx-pragma": "file:../babel-plugin-import-jsx-pragma", - "@wordpress/babel-plugin-makepot": "file:../babel-plugin-makepot", - "@wordpress/babel-preset-default": "file:../babel-preset-default", - "@wordpress/browserslist-config": "file:../browserslist-config", - "@wordpress/custom-templated-path-webpack-plugin": "file:../custom-templated-path-webpack-plugin", - "@wordpress/eslint-config": "file:../eslint-config", - "@wordpress/jest-console": "file:../jest-console", - "@wordpress/jest-preset-default": "file:../jest-preset-default", - "@wordpress/library-export-default-webpack-plugin": "file:../library-export-default-webpack-plugin", - "@wordpress/npm-package-json-lint-config": "file:../npm-package-json-lint-config", - "@wordpress/postcss-themes": "file:../postcss-themes", - "autoprefixer": "8.2.0", - "babel-loader": "8.0.0", - "chalk": "2.4.1", - "check-node-version": "3.1.1", - "concurrently": "3.5.0", - "core-js": "2.5.7", - "cross-env": "3.2.4", - "deasync": "0.1.13", - "deep-freeze": "0.0.1", - "doctrine": "2.1.0", - "eslint-plugin-jest": "21.5.0", - "espree": "3.5.4", - "glob": "7.1.2", - "husky": "0.14.3", - "jest-puppeteer": "3.2.1", - "lerna": "3.4.3", - "lint-staged": "7.2.0", - "lodash": "4.17.10", - "mkdirp": "0.5.1", - "node-sass": "4.9.2", - "path-type": "3.0.0", - "pegjs": "0.10.0", - "phpegjs": "1.0.0-beta7", - "postcss-color-function": "4.0.1", - "puppeteer": "1.6.1", - "react-test-renderer": "16.6.3", - "rimraf": "2.6.2", - "rtlcss": "2.4.0", - "sass-loader": "6.0.7", - "source-map-loader": "0.2.3", - "sprintf-js": "1.1.1", - "stylelint": "9.5.0", - "stylelint-config-wordpress": "13.1.0", - "symlink-or-copy": "1.2.0", - "uuid": "3.3.2", - "webpack": "4.8.3", - "webpack-bundle-analyzer": "3.0.2", - "webpack-cli": "2.1.3", - "webpack-livereload-plugin": "2.1.1", - "webpack-rtl-plugin": "github:yoavf/webpack-rtl-plugin#develop" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/webpack-config/.npmrc b/packages/webpack-config/.npmrc new file mode 100644 index 0000000000000..43c97e719a5a8 --- /dev/null +++ b/packages/webpack-config/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/packages/webpack-config/CHANGELOG.md b/packages/webpack-config/CHANGELOG.md new file mode 100644 index 0000000000000..16c97e5a1bf32 --- /dev/null +++ b/packages/webpack-config/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 (Unreleased) + +- Initial release. diff --git a/packages/webpack-config/README.md b/packages/webpack-config/README.md new file mode 100644 index 0000000000000..5602de2c9ed81 --- /dev/null +++ b/packages/webpack-config/README.md @@ -0,0 +1,13 @@ +# Webpack Config + +[Webpack](https://webpack.js.org/) config for WordPress development. + +## Installation + +Install the module + +```bash +npm install @wordpress/webpack-config --save-dev +``` + +

Code is Poetry.

diff --git a/packages/build-config/config/webpack.config.js b/packages/webpack-config/index.js similarity index 61% rename from packages/build-config/config/webpack.config.js rename to packages/webpack-config/index.js index 324aed68a0dff..4ab9659ced108 100644 --- a/packages/build-config/config/webpack.config.js +++ b/packages/webpack-config/index.js @@ -1,36 +1,8 @@ /** * External dependencies */ -const WebpackRTLPlugin = require( 'webpack-rtl-plugin' ); -const LiveReloadPlugin = require( 'webpack-livereload-plugin' ); - -const { get } = require( 'lodash' ); -const { basename } = require( 'path' ); - const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' ); - -/** - * WordPress dependencies - */ -const CustomTemplatedPathPlugin = require( '@wordpress/custom-templated-path-webpack-plugin' ); -const LibraryExportDefaultPlugin = require( '@wordpress/library-export-default-webpack-plugin' ); - -/** - * Given a string, returns a new string with dash separators converted to - * camelCase equivalent. This is not as aggressive as `_.camelCase` in - * converting to uppercase, where Lodash will also capitalize letters - * following numbers. - * - * @param {string} string Input dash-delimited string. - * - * @return {string} Camel-cased string. - */ -function camelCaseDash( string ) { - return string.replace( - /-([a-z])/g, - ( match, letter ) => letter.toUpperCase() - ); -} +const LiveReloadPlugin = require( 'webpack-livereload-plugin' ); /** * Converts @wordpress require into window reference @@ -67,8 +39,6 @@ const externals = [ jquery: 'jQuery', lodash: 'lodash', 'lodash-es': 'lodash', - electron: 'electron', - wp: 'wp', }, wordpressExternals, ]; @@ -87,7 +57,7 @@ const config = { externals, resolve: { modules: [ - __dirname, + process.cwd(), 'node_modules', ], alias: { @@ -113,40 +83,6 @@ const config = { ], }, plugins: [ - // Create RTL files with a -rtl suffix - new WebpackRTLPlugin( { - suffix: '-rtl', - minify: process.env.NODE_ENV === 'production' ? { safe: true } : false, - } ), - new CustomTemplatedPathPlugin( { - basename( path, data ) { - let rawRequest; - - const entryModule = get( data, [ 'chunk', 'entryModule' ], {} ); - switch ( entryModule.type ) { - case 'javascript/auto': - rawRequest = entryModule.rawRequest; - break; - - case 'javascript/esm': - rawRequest = entryModule.rootModule.rawRequest; - break; - } - - if ( rawRequest ) { - return basename( rawRequest ); - } - - return path; - }, - } ), - new LibraryExportDefaultPlugin( [ - 'api-fetch', - 'deprecated', - 'dom-ready', - 'redux-routine', - 'token-list', - ].map( camelCaseDash ) ), // GUTENBERG_BUNDLE_ANALYZER global variable enables utility that represents bundle content // as convenient interactive zoomable treemap. process.env.GUTENBERG_BUNDLE_ANALYZER && new BundleAnalyzerPlugin(), diff --git a/packages/webpack-config/package.json b/packages/webpack-config/package.json new file mode 100644 index 0000000000000..d87db2dade203 --- /dev/null +++ b/packages/webpack-config/package.json @@ -0,0 +1,32 @@ +{ + "name": "@wordpress/webpack-config", + "version": "1.0.0-alpha.0", + "description": "Webpack config for WordPress development.", + "author": "The WordPress Contributors", + "license": "GPL-2.0-or-later", + "keywords": [ + "wordpress", + "webpack", + "config" + ], + "homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/webpack-config/README.md", + "repository": { + "type": "git", + "url": "https://github.com/WordPress/gutenberg.git" + }, + "bugs": { + "url": "https://github.com/WordPress/gutenberg/issues" + }, + "engines": { + "node": ">=8", + "npm": ">=6.0.0" + }, + "main": "index.js", + "dependencies": { + "webpack-bundle-analyzer": "^3.0.3", + "webpack-livereload-plugin": "^2.2.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/webpack.config.js b/webpack.config.js index d54de2f47c017..a57a176d0fc81 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,13 +1,19 @@ /** * External dependencies */ +const WebpackRTLPlugin = require( 'webpack-rtl-plugin' ); const CopyWebpackPlugin = require( 'copy-webpack-plugin' ); const postcss = require( 'postcss' ); +const { get } = require( 'lodash' ); +const { basename } = require( 'path' ); + /** * WordPress dependencies */ -const webpackConfig = require( '@wordpress/build-config' ).webpackConfig; +const CustomTemplatedPathPlugin = require( '@wordpress/custom-templated-path-webpack-plugin' ); +const LibraryExportDefaultPlugin = require( '@wordpress/library-export-default-webpack-plugin' ); +const webpackConfig = require( '@wordpress/webpack-config' ); /** * Internal dependencies @@ -44,6 +50,40 @@ webpackConfig.entry = gutenbergPackages.reduce( ( memo, packageName ) => { }, {} ); webpackConfig.plugins.push( + // Create RTL files with a -rtl suffix + new WebpackRTLPlugin( { + suffix: '-rtl', + minify: process.env.NODE_ENV === 'production' ? { safe: true } : false, + } ), + new CustomTemplatedPathPlugin( { + basename( path, data ) { + let rawRequest; + + const entryModule = get( data, [ 'chunk', 'entryModule' ], {} ); + switch ( entryModule.type ) { + case 'javascript/auto': + rawRequest = entryModule.rawRequest; + break; + + case 'javascript/esm': + rawRequest = entryModule.rootModule.rawRequest; + break; + } + + if ( rawRequest ) { + return basename( rawRequest ); + } + + return path; + }, + } ), + new LibraryExportDefaultPlugin( [ + 'api-fetch', + 'deprecated', + 'dom-ready', + 'redux-routine', + 'token-list', + ].map( camelCaseDash ) ), new CopyWebpackPlugin( gutenbergPackages.map( ( packageName ) => ( { from: `./packages/${ packageName }/build-style/*.css`,