Browse Source

chore: compress code with babili

Gerald 8 years ago
parent
commit
39f91de394
6 changed files with 57 additions and 46 deletions
  1. 9 2
      gulpfile.js
  2. 19 17
      package.json
  3. 15 0
      scripts/utils.js
  4. 4 8
      scripts/webpack.conf.js
  5. 2 1
      scripts/webpack.test.conf.js
  6. 8 18
      src/.babelrc

+ 9 - 2
gulpfile.js

@@ -56,8 +56,15 @@ gulp.task('watch', ['pack', 'js-dev', 'svg'], () => {
 
 
 gulp.task('build', ['pack', 'js-prd', 'svg']);
 gulp.task('build', ['pack', 'js-prd', 'svg']);
 
 
-gulp.task('js-dev', () => webpack(webpackConfig).watch({}, webpackCallback));
-gulp.task('js-prd', () => webpack(webpackConfig, webpackCallback));
+gulp.task('js-dev', () => {
+  webpack(webpackConfig).watch({}, webpackCallback);
+});
+gulp.task('js-prd', cb => {
+  webpack(webpackConfig, (...args) => {
+    webpackCallback(...args);
+    cb();
+  });
+});
 
 
 gulp.task('manifest', () => (
 gulp.task('manifest', () => (
   gulp.src(paths.manifest, { base: 'src' })
   gulp.src(paths.manifest, { base: 'src' })

+ 19 - 17
package.json

@@ -16,42 +16,44 @@
   },
   },
   "description": "Violentmonkey",
   "description": "Violentmonkey",
   "devDependencies": {
   "devDependencies": {
-    "babel-core": "^6.24.1",
+    "babel-core": "^6.25.0",
     "babel-eslint": "^7.2.2",
     "babel-eslint": "^7.2.2",
     "babel-loader": "^7.0.0",
     "babel-loader": "^7.0.0",
     "babel-plugin-transform-export-extensions": "^6.22.0",
     "babel-plugin-transform-export-extensions": "^6.22.0",
     "babel-plugin-transform-runtime": "^6.23.0",
     "babel-plugin-transform-runtime": "^6.23.0",
+    "babel-preset-env": "^1.5.2",
     "babel-preset-es2015": "^6.24.1",
     "babel-preset-es2015": "^6.24.1",
-    "css-loader": "^0.28.0",
-    "del": "^2.2.0",
+    "babili-webpack-plugin": "^0.1.1",
+    "css-loader": "^0.28.4",
+    "del": "^3.0.0",
     "es6-promisify": "^5.0.0",
     "es6-promisify": "^5.0.0",
     "eslint": "^3.19.0",
     "eslint": "^3.19.0",
-    "eslint-config-airbnb-base": "^11.1.3",
-    "eslint-friendly-formatter": "^2.0.7",
+    "eslint-config-airbnb-base": "^11.2.0",
+    "eslint-friendly-formatter": "^3.0.0",
     "eslint-import-resolver-webpack": "^0.8.1",
     "eslint-import-resolver-webpack": "^0.8.1",
     "eslint-loader": "^1.7.1",
     "eslint-loader": "^1.7.1",
-    "eslint-plugin-html": "^2.0.1",
-    "eslint-plugin-import": "^2.2.0",
-    "extract-text-webpack-plugin": "^2.1.0",
+    "eslint-plugin-html": "^2.0.3",
+    "eslint-plugin-import": "^2.3.0",
+    "extract-text-webpack-plugin": "^2.1.2",
     "friendly-errors-webpack-plugin": "^1.6.1",
     "friendly-errors-webpack-plugin": "^1.6.1",
     "gulp": "^3.9.1",
     "gulp": "^3.9.1",
     "gulp-filter": "^5.0.0",
     "gulp-filter": "^5.0.0",
-    "gulp-svg-sprite": "^1.2.19",
+    "gulp-svg-sprite": "^1.3.7",
     "gulp-uglify": "^2.0.0",
     "gulp-uglify": "^2.0.0",
     "gulp-util": "^3.0.7",
     "gulp-util": "^3.0.7",
     "html-webpack-plugin": "^2.28.0",
     "html-webpack-plugin": "^2.28.0",
-    "husky": "^0.13.3",
-    "js-yaml": "^3.8.3",
+    "husky": "^0.13.4",
+    "js-yaml": "^3.8.4",
     "localStorage": "^1.0.3",
     "localStorage": "^1.0.3",
     "precss": "^1.4.0",
     "precss": "^1.4.0",
     "svgo": "^0.7.2",
     "svgo": "^0.7.2",
     "tape": "^4.6.3",
     "tape": "^4.6.3",
     "through2": "^2.0.3",
     "through2": "^2.0.3",
-    "vue-loader": "^12.0.2",
+    "vue-loader": "^12.2.1",
     "vue-style-loader": "^3.0.1",
     "vue-style-loader": "^3.0.1",
-    "vue-template-compiler": "^2.3.0",
-    "webpack": "^2.4.1",
-    "webpack-bundle-size-analyzer": "^2.6.0"
+    "vue-template-compiler": "^2.3.4",
+    "webpack": "^2.6.1",
+    "webpack-bundle-size-analyzer": "^2.7.0"
   },
   },
   "author": "Gerald <[email protected]>",
   "author": "Gerald <[email protected]>",
   "repository": {
   "repository": {
@@ -64,10 +66,10 @@
   "homepage": "https://github.com/violentmonkey/violentmonkey",
   "homepage": "https://github.com/violentmonkey/violentmonkey",
   "license": "MIT",
   "license": "MIT",
   "dependencies": {
   "dependencies": {
-    "codemirror": "^5.25.2",
+    "codemirror": "^5.26.0",
     "core-js": "^2.4.1",
     "core-js": "^2.4.1",
     "sync-promise-lite": "^0.2.3",
     "sync-promise-lite": "^0.2.3",
-    "vue": "^2.3.0",
+    "vue": "^2.3.4",
     "vue-code": "^1.2.1"
     "vue-code": "^1.2.1"
   }
   }
 }
 }

+ 15 - 0
scripts/utils.js

@@ -28,6 +28,21 @@ function styleRule(options = {}) {
   };
   };
 }
 }
 
 
+function merge(obj1, obj2) {
+  if (!obj2) return obj1;
+  if (Array.isArray(obj1)) return obj1.concat(obj2);
+  const obj = Object.assign({}, obj1);
+  Object.keys(obj2).forEach(key => {
+    if (typeof obj[key] === 'object') {
+      obj[key] = merge(obj[key], obj2[key]);
+    } else {
+      obj[key] = obj2[key];
+    }
+  });
+  return obj;
+}
+
 exports.IS_DEV = IS_DEV;
 exports.IS_DEV = IS_DEV;
 exports.styleLoader = styleLoader;
 exports.styleLoader = styleLoader;
 exports.styleRule = styleRule;
 exports.styleRule = styleRule;
+exports.merge = merge;

+ 4 - 8
scripts/webpack.conf.js

@@ -2,8 +2,9 @@ const webpack = require('webpack');
 const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
 const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
 const ExtractTextPlugin = require('extract-text-webpack-plugin');
 const ExtractTextPlugin = require('extract-text-webpack-plugin');
 const HtmlWebpackPlugin = require('html-webpack-plugin');
 const HtmlWebpackPlugin = require('html-webpack-plugin');
+const BabiliWebpackPlugin = require('babili-webpack-plugin');
 const base = require('./webpack.base.conf');
 const base = require('./webpack.base.conf');
-const { IS_DEV } = require('./utils');
+const { IS_DEV, merge } = require('./utils');
 
 
 const entry = {
 const entry = {
   'background/app': 'src/background/app.js',
   'background/app': 'src/background/app.js',
@@ -12,10 +13,9 @@ const entry = {
   injected: 'src/injected/index.js',
   injected: 'src/injected/index.js',
 };
 };
 
 
-module.exports = Object.assign({}, base, {
+module.exports = merge(base, {
   entry,
   entry,
   plugins: [
   plugins: [
-    ... base.plugins,
     new webpack.optimize.CommonsChunkPlugin({
     new webpack.optimize.CommonsChunkPlugin({
       name: 'browser',
       name: 'browser',
       chunks: Object.keys(entry),
       chunks: Object.keys(entry),
@@ -51,11 +51,7 @@ module.exports = Object.assign({}, base, {
     ] : [
     ] : [
       // extract css into its own file
       // extract css into its own file
       new ExtractTextPlugin('[name].css'),
       new ExtractTextPlugin('[name].css'),
-      new webpack.optimize.UglifyJsPlugin({
-        compress: {
-          warnings: false
-        }
-      }),
+      new BabiliWebpackPlugin(),
     ],
     ],
   ],
   ],
   externals: {
   externals: {

+ 2 - 1
scripts/webpack.test.conf.js

@@ -1,7 +1,8 @@
 const webpack = require('webpack');
 const webpack = require('webpack');
 const base = require('./webpack.base.conf');
 const base = require('./webpack.base.conf');
+const { merge } = require('./utils');
 
 
-module.exports = Object.assign({}, base, {
+module.exports = merge(base, {
   target: 'node',
   target: 'node',
   entry: {
   entry: {
     test: './test',
     test: './test',

+ 8 - 18
src/.babelrc

@@ -1,27 +1,17 @@
 {
 {
+  "presets": [
+    ["env", {
+      "modules": false,
+      "targets": {
+        "browsers": ["chrome >= 45"]
+      }
+    }],
+  ],
   "plugins": [
   "plugins": [
     ["transform-runtime", {
     ["transform-runtime", {
       "polyfill": false,
       "polyfill": false,
       // "helpers": false,
       // "helpers": false,
     }],
     }],
-    "transform-es2015-template-literals",
-    "transform-es2015-literals",
-    "transform-es2015-function-name",
-    "transform-es2015-arrow-functions",
-    "transform-es2015-block-scoped-functions",
-    "transform-es2015-classes",
-    "transform-es2015-object-super",
-    "transform-es2015-shorthand-properties",
-    "transform-es2015-duplicate-keys",
-    "transform-es2015-computed-properties",
-    "transform-es2015-for-of",
-    "transform-es2015-sticky-regex",
-    "transform-es2015-unicode-regex",
-    "check-es2015-constants",
-    "transform-es2015-spread",
-    "transform-es2015-parameters",
-    "transform-es2015-destructuring",
-    "transform-es2015-block-scoping",
     "transform-export-extensions",
     "transform-export-extensions",
   ],
   ],
   "comments": false
   "comments": false