diff --git a/gulpfile.js b/gulpfile.js index 1f9452eecf..a2ce64c76c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,7 +7,6 @@ const fs = require('fs'); const path = require('path'); const https = require('https'); const gulp = require('gulp'); -const yargs = require('yargs'); const concat = require('gulp-concat'); const sourcemaps = require('gulp-sourcemaps'); const cssnano = require('cssnano'); @@ -45,9 +44,6 @@ forOwn(supportedBrowsers, (version, browser) => { gulp.task('env', () => { process.env.GIT_REVISION = git.short(); - if (yargs.argv.production) { - process.env.NODE_ENV = 'production'; - } }); gulp.task('static', () => gulp. @@ -93,24 +89,7 @@ gulp.task('css', () => { pipe(browserSync.stream()); }); -gulp.task('js', ['env'], () => { - const productionWebpackConfig = Object.create(webpackConfiguration); - productionWebpackConfig.plugins = productionWebpackConfig.plugins.concat( - new webpack.DefinePlugin({ - 'process.env': { - NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'), - }, - }), - new webpack.optimize.DedupePlugin(), - new webpack.optimize.UglifyJsPlugin({ - compress: {warnings: false}, - output: {comments: false}, - sourceMap: true, - }), - ); - - return pify(webpack)(productionWebpackConfig); -}); +gulp.task('js', ['env'], () => pify(webpack)(webpackConfiguration)); gulp.task('build', ['static', 'fonts', 'css', 'js']); diff --git a/package.json b/package.json index 674d45e0cc..35bbfd29c5 100644 --- a/package.json +++ b/package.json @@ -173,6 +173,7 @@ "postinstall": "bower install", "pretest": "yarn run lint", "dev": "yarn install && gulp dev", + "prod": "yarn install && NODE_ENV=production gulp build", "test": "karma start --single-run --no-auto-watch", "autotest": "karma start --no-single-run --auto-watch", "lint": "eslint --ext .js,.jsx --plugin react src test *.js && stylelint src/**/*.css", @@ -249,8 +250,7 @@ "webpack": "^3.1.0", "webpack-chunk-hash": "^0.4.0", "webpack-dev-middleware": "^1.8.2", - "webpack-hot-middleware": "^2.12.2", - "yargs": "^8.0.1" + "webpack-hot-middleware": "^2.12.2" }, "optionalDependencies": { "fsevents": "*" diff --git a/webpack.config.js b/webpack.config.js index b51a641f29..03fec28f48 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -20,6 +20,8 @@ const babel = require('babel-core'); const babelLoaderVersion = require('./node_modules/babel-loader/package.json').version; +const isProduction = process.env.NODE_ENV === 'production'; + let targets; if (process.env.DEBUG === 'true') { targets = {browsers: 'last 1 Chrome version'}; @@ -70,12 +72,8 @@ module.exports = { entry: './src/application.js', output: { path: path.resolve(__dirname, './dist'), - filename: process.env.NODE_ENV === 'production' ? - '[name].[chunkhash].js' : - '[name].js', - chunkFilename: process.env.NODE_ENV === 'production' ? - '[name].[chunkhash].js' : - '[name].js', + filename: isProduction ? '[name].[chunkhash].js' : '[name].js', + chunkFilename: isProduction ? '[name].[chunkhash].js' : '[name].js', }, module: { rules: [ @@ -261,6 +259,17 @@ module.exports = { ], ServiceWorker: {navigateFallbackURL: '/'}, }), + new webpack.DefinePlugin({ + 'process.env': { + NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'), + }, + }), + new webpack.optimize.DedupePlugin(), + new webpack.optimize.UglifyJsPlugin({ + compress: {warnings: false}, + output: {comments: false}, + sourceMap: true, + }), new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', minChunks({context}) { @@ -273,7 +282,7 @@ module.exports = { }, }), new webpack.optimize.CommonsChunkPlugin({name: 'manifest'}), - process.env.NODE_ENV === 'production' ? + isProduction ? new webpack.HashedModuleIdsPlugin() : new webpack.NamedModulesPlugin(), new MD5ChunkHash(), diff --git a/yarn.lock b/yarn.lock index 6ff70b2b5e..6d8d3c565f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9529,7 +9529,7 @@ yargs@6.4.0: y18n "^3.2.1" yargs-parser "^4.1.0" -yargs@^8.0.1, yargs@^8.0.2: +yargs@^8.0.2: version "8.0.2" resolved "https://registry.yarnpkg.com/yargs/-/yargs-8.0.2.tgz#6299a9055b1cefc969ff7e79c1d918dceb22c360" dependencies: