From f173141c5b8a80f063b7ae30cab2a00da4e2cbb7 Mon Sep 17 00:00:00 2001 From: Anton Timmermans Date: Tue, 11 Dec 2018 16:38:21 +0000 Subject: [PATCH] Build tools: Combine webpack config files. This prepares us for building the Gutenberg packages. Merges [43687] to trunk. See #45065. git-svn-id: https://develop.svn.wordpress.org/trunk@43978 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 8 ++---- webpack.config.dev.js => webpack.config.js | 15 +++++++--- webpack.config.prod.js | 33 ---------------------- 3 files changed, 14 insertions(+), 42 deletions(-) rename webpack.config.dev.js => webpack.config.js (80%) delete mode 100644 webpack.config.prod.js diff --git a/Gruntfile.js b/Gruntfile.js index a77384423c..24d1282d3e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,7 +1,6 @@ /* jshint node:true */ /* globals Set */ -var webpackConfig = require( './webpack.config.prod' ); -var webpackDevConfig = require( './webpack.config.dev' ); +var webpackConfig = require( './webpack.config' ); module.exports = function(grunt) { var path = require('path'), @@ -704,8 +703,8 @@ module.exports = function(grunt) { } }, webpack: { - prod: webpackConfig, - dev: webpackDevConfig + prod: webpackConfig( { environment: 'production' } ), + dev: webpackConfig( { environment: 'development' } ) }, concat: { tinymce: { @@ -1090,7 +1089,6 @@ module.exports = function(grunt) { config: { files: [ 'Gruntfile.js', - 'webpack-dev.config.js', 'webpack.config.js' ] }, diff --git a/webpack.config.dev.js b/webpack.config.js similarity index 80% rename from webpack.config.dev.js rename to webpack.config.js index cf6fa9ea88..39bc8f3672 100644 --- a/webpack.config.dev.js +++ b/webpack.config.js @@ -14,10 +14,11 @@ include_files = { 'build/wp-includes/js/media-views.min.js': ['./src/js/_enqueues/wp/media/views.js'], }; -module.exports = [ - { +module.exports = function( env = { environment: "production" } ) { + const mode = env.environment; + + const mediaConfig = { cache: true, - watch: false, entry: Object.assign( admin_files, include_files ), output: { filename: '[name]', @@ -28,5 +29,11 @@ module.exports = [ minimize: true }) ] + }; + + if ( mode === 'production' ) { + mediaConfig.plugins.push( new webpack.optimize.ModuleConcatenationPlugin() ); } -]; + + return mediaConfig; +}; diff --git a/webpack.config.prod.js b/webpack.config.prod.js deleted file mode 100644 index e6ba61f27e..0000000000 --- a/webpack.config.prod.js +++ /dev/null @@ -1,33 +0,0 @@ -var path = require( 'path' ), - webpack = require( 'webpack' ), - admin_files = {}, - include_files = {}; - -include_files = { - 'build/wp-includes/js/media-audiovideo.js': ['./src/js/_enqueues/wp/media/audiovideo.js'], - 'build/wp-includes/js/media-audiovideo.min.js': ['./src/js/_enqueues/wp/media/audiovideo.js'], - 'build/wp-includes/js/media-grid.js': ['./src/js/_enqueues/wp/media/grid.js'], - 'build/wp-includes/js/media-grid.min.js': ['./src/js/_enqueues/wp/media/grid.js'], - 'build/wp-includes/js/media-models.js': ['./src/js/_enqueues/wp/media/models.js'], - 'build/wp-includes/js/media-models.min.js': ['./src/js/_enqueues/wp/media/models.js'], - 'build/wp-includes/js/media-views.js': ['./src/js/_enqueues/wp/media/views.js'], - 'build/wp-includes/js/media-views.min.js': ['./src/js/_enqueues/wp/media/views.js'], -}; - -module.exports = [ - { - cache: true, - watch: false, - entry: Object.assign( admin_files, include_files ), - output: { - filename: '[name]', - }, - plugins: [ - new webpack.optimize.ModuleConcatenationPlugin(), - new webpack.optimize.UglifyJsPlugin({ - include: /\.min\.js$/, - minimize: true - }) - ] - } -];