Răsfoiți Sursa

chore: decrease package size

Gerald 8 ani în urmă
părinte
comite
f3758e5b3e

+ 1 - 1
gulpfile.js

@@ -37,7 +37,7 @@ function webpackCallback(err, stats) {
   if (stats.hasWarnings()) {
     gutil.log('[WARNING] webpack compilation has warnings\n', stats.toJson().warnings.join('\n'));
   }
-  stats.stats.forEach(stat => {
+  [stats].forEach(stat => {
     const timeCost = (stat.endTime - stat.startTime) / 1000;
     const chunks = Object.keys(stat.compilation.namedChunks).join(' ');
     gutil.log(`Webpack built: [${timeCost.toFixed(3)}s] ${chunks}`);

+ 17 - 29
scripts/webpack.conf.js

@@ -5,40 +5,45 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
 const base = require('./webpack.base.conf');
 const { IS_DEV } = require('./utils');
 
-const targets = module.exports = [];
+const entry = {
+  'background/app': 'src/background/app.js',
+  'options/app': 'src/options/app.js',
+  'popup/app': 'src/popup/app.js',
+  injected: 'src/injected/index.js',
+};
 
-targets.push(Object.assign({}, base, {
-  entry: {
-    'background/app': 'src/background/app.js',
-    'options/app': 'src/options/app.js',
-    'popup/app': 'src/popup/app.js',
-  },
+module.exports = Object.assign({}, base, {
+  entry,
   plugins: [
     ... base.plugins,
-    // split vendor js into its own file
+    new webpack.optimize.CommonsChunkPlugin({
+      name: 'browser',
+      chunks: Object.keys(entry),
+    }),
     new webpack.optimize.CommonsChunkPlugin({
       name: 'vendor',
+      chunks: Object.keys(entry).filter(key => key !== 'injected'),
       minChunks: 2,
     }),
     new HtmlWebpackPlugin({
       filename: 'background/index.html',
       template: 'src/background/index.html',
       inject: true,
-      chunks: ['vendor', 'background/app'],
+      chunks: ['vendor', 'browser', 'background/app'],
       chunksSortMode: 'dependency'
     }),
     new HtmlWebpackPlugin({
       filename: 'options/index.html',
       template: 'src/options/index.html',
       inject: true,
-      chunks: ['vendor', 'options/app'],
+      chunks: ['vendor', 'browser', 'options/app'],
       chunksSortMode: 'dependency'
     }),
     new HtmlWebpackPlugin({
       filename: 'popup/index.html',
       template: 'src/popup/index.html',
       inject: true,
-      chunks: ['vendor', 'popup/app'],
+      chunks: ['vendor', 'browser', 'popup/app'],
       chunksSortMode: 'dependency'
     }),
     // new FriendlyErrorsPlugin(),
@@ -56,21 +61,4 @@ targets.push(Object.assign({}, base, {
   externals: {
     localStorage: 'localStorage',
   },
-}));
-
-targets.push(Object.assign({}, base, {
-  entry: {
-    injected: 'src/injected/index.js',
-    browser: 'src/browser.js',
-  },
-  plugins: [
-    ... base.plugins,
-    ... IS_DEV ? [] : [
-      new webpack.optimize.UglifyJsPlugin({
-        compress: {
-          warnings: false
-        }
-      }),
-    ],
-  ],
-}));
+});

+ 1 - 0
src/background/app.js

@@ -1,3 +1,4 @@
+import 'src/common/browser';
 import { i18n, defaultImage } from 'src/common';
 import * as sync from './sync';
 import {

+ 0 - 1
src/background/index.html

@@ -3,7 +3,6 @@
 <head>
 <meta charset="utf-8">
 <title>ViolentMonkey</title>
-<script src="/browser.js"></script>
 </head>
 <body></body>
 </html>

+ 2 - 0
src/browser.js → src/common/browser.js

@@ -1,3 +1,5 @@
+import './polyfills';
+
 /* global chrome */
 const global = window;
 

+ 0 - 2
src/common/index.js

@@ -1,5 +1,3 @@
-import './polyfills';
-
 export function i18n(name, args) {
   return browser.i18n.getMessage(name, args) || name;
 }

+ 1 - 0
src/injected/index.js

@@ -1,3 +1,4 @@
+import 'src/common/browser';
 import { inject, objEncode, getUniqId, sendMessage } from './utils';
 import { onNotificationClick, onNotificationClose } from './notification';
 import { httpRequested } from './requests';

+ 1 - 0
src/options/app.js

@@ -1,4 +1,5 @@
 import Vue from 'vue';
+import 'src/common/browser';
 import 'src/common/sprite';
 import { sendMessage, i18n } from 'src/common';
 import options from 'src/common/options';

+ 0 - 1
src/options/index.html

@@ -6,7 +6,6 @@
 <link rel="icon" type="image/png" href="/public/images/icon32.png" sizes="32x32">
 <link rel="icon" type="image/png" href="/public/images/icon16.png" sizes="16x16">
 <script src="/public/lib/zip.js/zip.js"></script>
-<script src="/browser.js"></script>
 </head>
 <body>
 <div id="app"></div>

+ 1 - 0
src/popup/app.js

@@ -1,4 +1,5 @@
 import Vue from 'vue';
+import 'src/common/browser';
 import 'src/common/sprite';
 import options from 'src/common/options';
 import { i18n, sendMessage } from 'src/common';

+ 0 - 1
src/popup/index.html

@@ -3,7 +3,6 @@
 <head>
 <meta charset="utf-8">
 <title>Popup Menu - Violentmonkey</title>
-<script src="/browser.js"></script>
 </head>
 <body>
 <div id="app"></div>