Ticket #49423: 49423-latest.diff
File 49423-latest.diff, 6.0 KB (added by , 4 years ago) |
---|
-
package.json
69 69 "sinon": "~9.0.0", 70 70 "sinon-test": "~3.0.0", 71 71 "source-map-loader": "^0.2.4", 72 "uglify-js": "^3.6.0",73 72 "uglifyjs-webpack-plugin": "2.2.0", 74 73 "wait-on": "3.3.0", 75 74 "webpack": "4.43.0", -
tools/webpack/packages.js
5 5 const CopyWebpackPlugin = require( 'copy-webpack-plugin' ); 6 6 const LiveReloadPlugin = require( 'webpack-livereload-plugin' ); 7 7 const postcss = require( 'postcss' ); 8 const UglifyJS = require( 'uglify-js' );9 8 10 9 const { join, basename } = require( 'path' ); 11 10 const { get } = require( 'lodash' ); … … 41 40 ); 42 41 } 43 42 44 /**45 * Maps vendors to copy commands for the CopyWebpackPlugin.46 *47 * @param {Object} vendors Vendors to include in the vendor folder.48 * @param {string} buildTarget The folder in which to build the packages.49 *50 * @return {Object[]} Copy object suitable for the CopyWebpackPlugin.51 */52 function mapVendorCopies( vendors, buildTarget ) {53 return Object.keys( vendors ).map( ( filename ) => ( {54 from: join( baseDir, `node_modules/${ vendors[ filename ] }` ),55 to: join( baseDir, `${ buildTarget }/js/dist/vendor/${ filename }` ),56 } ) );57 }58 43 59 44 module.exports = function( env = { environment: 'production', watch: false, buildTarget: false } ) { 60 45 const mode = env.environment; … … 71 56 ) 72 57 .map( ( packageName ) => packageName.replace( WORDPRESS_NAMESPACE, '' ) ); 73 58 74 const vendors = {75 'lodash.js': 'lodash/lodash.js',76 'wp-polyfill.js': '@babel/polyfill/dist/polyfill.js',77 'wp-polyfill-fetch.js': 'whatwg-fetch/dist/fetch.umd.js',78 'wp-polyfill-element-closest.js': 'element-closest/element-closest.js',79 'wp-polyfill-node-contains.js': 'polyfill-library/polyfills/Node/prototype/contains/polyfill.js',80 'wp-polyfill-url.js': 'core-js-url-browser/url.js',81 'wp-polyfill-dom-rect.js': 'polyfill-library/polyfills/DOMRect/polyfill.js',82 'wp-polyfill-formdata.js': 'formdata-polyfill/FormData.js',83 'moment.js': 'moment/moment.js',84 'react.js': 'react/umd/react.development.js',85 'react-dom.js': 'react-dom/umd/react-dom.development.js',86 };87 88 const minifiedVendors = {89 'lodash.min.js': 'lodash/lodash.min.js',90 'wp-polyfill.min.js': '@babel/polyfill/dist/polyfill.min.js',91 'wp-polyfill-formdata.min.js': 'formdata-polyfill/formdata.min.js',92 'wp-polyfill-url.min.js': 'core-js-url-browser/url.min.js',93 'moment.min.js': 'moment/min/moment.min.js',94 'react.min.js': 'react/umd/react.production.min.js',95 'react-dom.min.js': 'react-dom/umd/react-dom.production.min.js',96 };97 98 const minifyVendors = {99 'wp-polyfill-fetch.min.js': 'whatwg-fetch/dist/fetch.umd.js',100 'wp-polyfill-element-closest.min.js': 'element-closest/element-closest.js',101 'wp-polyfill-node-contains.min.js': 'polyfill-library/polyfills/Node/prototype/contains/polyfill.js',102 'wp-polyfill-dom-rect.min.js': 'polyfill-library/polyfills/DOMRect/polyfill.js',103 };104 105 59 const dynamicBlockFolders = [ 106 60 'archives', 107 61 'block', … … 162 116 } , {} ), 163 117 }; 164 118 165 const developmentCopies = mapVendorCopies( vendors, buildTarget );166 const minifiedCopies = mapVendorCopies( minifiedVendors, buildTarget );167 const minifyCopies = mapVendorCopies( minifyVendors, buildTarget ).map( ( copyCommand ) => {168 return {169 ...copyCommand,170 transform: ( content ) => {171 return UglifyJS.minify( content.toString() ).code;172 },173 };174 } );175 176 let vendorCopies = mode === "development" ? developmentCopies : [ ...minifiedCopies, ...minifyCopies ];177 178 119 let cssCopies = packages.map( ( packageName ) => ( { 179 120 from: join( baseDir, `node_modules/@wordpress/${ packageName }/build-style/*.css` ), 180 121 to: join( baseDir, `${ buildTarget }/css/dist/${ packageName }/` ), … … 290 231 } ), 291 232 new CopyWebpackPlugin( 292 233 [ 293 ...vendorCopies,294 234 ...cssCopies, 295 235 ...phpCopies, 296 236 ...blockMetadataCopies, -
tools/webpack/vendor.js
1 /** 2 * External dependencies 3 */ 4 const { join } = require( 'path' ); 5 6 module.exports = function( env = { environment: 'production', watch: false, buildTarget: false } ) { 7 const mode = env.environment; 8 const suffix = mode === 'production' ? '.min' : ''; 9 const buildTarget = env.buildTarget || ( mode === 'production' ? 'build' : 'src' ); 10 11 return { 12 mode, 13 14 entry: { 15 lodash: 'lodash', 16 'wp-polyfill': '@babel/polyfill', 17 'wp-polyfill-fetch': 'whatwg-fetch', 18 'wp-polyfill-element-closest': 'element-closest', 19 'wp-polyfill-node-contains': 'polyfill-library/polyfills/Node/prototype/contains/polyfill.js', 20 'wp-polyfill-url': 'core-js-url-browser', 21 'wp-polyfill-dom-rect': 'polyfill-library/polyfills/DOMRect/polyfill.js', 22 'wp-polyfill-formdata': 'formdata-polyfill', 23 'moment': 'moment', 24 'react': 'react', 25 'react-dom': 'react-dom', 26 }, 27 28 output: { 29 filename: `[name]${ suffix }.js`, 30 path: join( __dirname, `../../${ buildTarget }/wp-includes/js/dist/vendor` ), 31 }, 32 33 stats: { 34 children: false, 35 }, 36 37 watch: env.watch, 38 }; 39 }; -
webpack.config.js
1 1 const mediaConfig = require( './tools/webpack/media' ); 2 2 const packagesConfig = require( './tools/webpack/packages' ); 3 const vendorConfig = require( './tools/webpack/vendor' ); 3 4 4 5 module.exports = function( env = { environment: "production", watch: false, buildTarget: false } ) { 5 6 if ( ! env.watch ) { … … 13 14 const config = [ 14 15 mediaConfig( env ), 15 16 packagesConfig( env ), 17 vendorConfig( env ), 16 18 ]; 17 19 18 20 return config;