Browse Source

chore: add env MINIFY to enable compression

close #162
Gerald 8 years ago
parent
commit
6d19de6065
3 changed files with 13 additions and 3 deletions
  1. 1 1
      README.md
  2. 2 1
      package.json
  3. 10 1
      scripts/webpack.base.conf.js

+ 1 - 1
README.md

@@ -30,5 +30,5 @@ Build
 $ npm run build
 
 # Build a compressed version
-$ npm run build --production
+$ npm run build:min
 ```

+ 2 - 1
package.json

@@ -4,7 +4,8 @@
   "scripts": {
     "dev": "gulp watch",
     "prebuild": "npm run lint && gulp clean",
-    "build": "gulp build",
+    "build": "NODE_ENV=production gulp build",
+    "build:min": "MINIFY=true NODE_ENV=production gulp build",
     "analyze": "webpack --profile --json --config scripts/webpack.conf.js | webpack-bundle-size-analyzer",
     "analyze:json": "webpack --profile --json --config scripts/webpack.conf.js > stats.json",
     "i18n": "gulp i18n",

+ 10 - 1
scripts/webpack.base.conf.js

@@ -1,8 +1,11 @@
 const path = require('path');
 const webpack = require('webpack');
 const BabiliWebpackPlugin = require('babili-webpack-plugin');
+const babiliPreset = require('babel-preset-babili');
 const vueLoaderConfig = require('./vue-loader.conf');
 const { IS_DEV, styleRule } = require('./utils');
+
+const { MINIFY } = process.env;
 const DIST = 'dist';
 const definePlugin = new webpack.DefinePlugin({
   'process.env': {
@@ -58,6 +61,12 @@ module.exports = {
   devtool: IS_DEV ? '#inline-source-map' : false,
   plugins: [
     definePlugin,
-    !IS_DEV && new BabiliWebpackPlugin(),
+    !IS_DEV && new BabiliWebpackPlugin({
+      mangle: !!MINIFY,
+    }, {
+      babili: (...args) => Object.assign(babiliPreset(...args), {
+        minified: !!MINIFY,
+      }),
+    }),
   ].filter(Boolean),
 };