From f59565889573f1cded03fbc79e6f503d5a7e0ba5 Mon Sep 17 00:00:00 2001 From: Justin Anastos Date: Fri, 14 Apr 2017 10:36:24 -0400 Subject: [PATCH] chore(webpack) only apply transform-runtime to prod build This will allow this package to `npm-link`'ed. --- .babelrc | 12 +++++++++--- package.json | 1 + webpack/webpack.config.production.js | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.babelrc b/.babelrc index ca2f118..692cd63 100644 --- a/.babelrc +++ b/.babelrc @@ -1,9 +1,15 @@ { "plugins": [ - "transform-object-rest-spread", - "transform-runtime" + "transform-object-rest-spread" ], "presets": [ "es2015" - ] + ], + "env": { + "production": { + "plugins": [ + "transform-runtime" + ] + } + } } diff --git a/package.json b/package.json index 68495e5..f3254c6 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "karma-phantomjs-launcher": "^1.0.4", "karma-webpack": "^1.8.0", "load-grunt-tasks": "^3.5.2", + "lodash": "^4.17.4", "moment": "^2.14.1", "node-sass": "^3.8.0", "null-loader": "^0.1.1", diff --git a/webpack/webpack.config.production.js b/webpack/webpack.config.production.js index 040d3b8..937a7e1 100644 --- a/webpack/webpack.config.production.js +++ b/webpack/webpack.config.production.js @@ -1,5 +1,6 @@ const CleanWebpackPlugin = require('clean-webpack-plugin'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const merge = require('lodash/merge'); const path = require('path'); const webpack = require('webpack'); const webpackConfig = require('./webpack.config'); @@ -20,6 +21,23 @@ webpackConfig.module.loaders = [{ test: /\.scss$/, }]; +// Add `forceEnv: 'prod'` to all babel postLoaders +webpackConfig.module.postLoaders = webpackConfig.module.postLoaders.map((loader) => { + if (loader.loader.indexOf('babel') !== 0) { + return loader; + } + + return merge( + {}, + loader, + { + query: { + forceEnv: 'production', + }, + } + ); +}); + webpackConfig.plugins = [ new CleanWebpackPlugin('dist', { root: path.resolve(__dirname, '..'),