浏览代码

公共文件的打包使用 dll 方式抽离。

oldj 8 年之前
父节点
当前提交
8aeadd2f82

+ 5 - 1
README.md

@@ -60,17 +60,21 @@ SwitchHosts! 的数据文件在 `~/.SwitchHosts` 目录下(Windows 用户为
 
 ### 构建及运行
 
+ - 在 `./` 目录下,运行 `npm run dll` 命令,构建公共文件(仅在第一次构建或公共库发生改变时执行);
  - 在 `./` 目录下,运行 `npm run build` 命令,构建所需文件;
  - 在 `./` 目录下,运行 `npm start` 命令,即可运行程序。
 
     ```bash
+    # create dll file
+    npm run dll
+ 
     # build
     npm run build
 
     # start
     npm start
 
-    # start in developer mode
+    # or start in developer mode
     npm run dev
     ```
 

+ 1 - 1
app/main.js

@@ -43,7 +43,7 @@ function createWindow () {
   app.mainWindow = mainWindow
 
   // and load the index.html of the app.
-  mainWindow.loadURL(`file://${__dirname}/index.html?lang=${user_language}`)
+  mainWindow.loadURL(`file://${__dirname}/ui/index.html?lang=${user_language}`)
 
   if (process.env && process.env.ENV === 'dev') {
     // Open the DevTools.

文件差异内容过多而无法显示
+ 0 - 1
app/static/bundle.js


文件差异内容过多而无法显示
+ 0 - 1
app/static/common.js


文件差异内容过多而无法显示
+ 1 - 0
app/ui/bundle.js


+ 0 - 0
app/static/iconfont-524781dfef675a4af82dd14fd6f9e12f.woff → app/ui/iconfont-524781dfef675a4af82dd14fd6f9e12f.woff


+ 0 - 0
app/static/iconfont-a40b6b285526376dbeb09b6cb766b932.ttf → app/ui/iconfont-a40b6b285526376dbeb09b6cb766b932.ttf


+ 0 - 0
app/static/iconfont-da59b3e69b878c9490fb7d7bc65761b0.eot → app/ui/iconfont-da59b3e69b878c9490fb7d7bc65761b0.eot


+ 0 - 0
app/static/iconfont-f876b6a3ea1f4a97d8e118654b4a8984.svg → app/ui/iconfont-f876b6a3ea1f4a97d8e118654b4a8984.svg


+ 2 - 2
app/index.html → app/ui/index.html

@@ -6,7 +6,7 @@
 </head>
 <body>
 <div id="app"></div>
-<script src="./static/common.js"></script>
-<script src="./static/bundle.js"></script>
+<script src="./lib.js"></script>
+<script src="./bundle.js"></script>
 </body>
 </html>

文件差异内容过多而无法显示
+ 1 - 0
app/ui/lib.js


+ 1 - 1
app/version.js

@@ -1 +1 @@
-exports.version = [3,3,5,5258];
+exports.version = [3,3,5,5262];

+ 1 - 0
package.json

@@ -7,6 +7,7 @@
     "_ln": "./scripts/ln.sh",
     "test": "nyc ava",
     "start": "electron app",
+    "dll": "webpack --config scripts/webpack.dll.js --progress --profile --colors",
     "dev": "ENV=dev electron app",
     "build": "gulp ver && webpack --progress --profile --colors",
     "pack": "gulp pack",

+ 44 - 0
scripts/webpack.dll.js

@@ -0,0 +1,44 @@
+/**
+ * @author oldj
+ * @blog https://oldj.net
+ */
+
+'use strict'
+
+const path = require('path')
+const webpack = require('webpack')
+const moment = require('moment')
+const basedir = path.dirname(__dirname)
+
+const vendors = [
+  'react', 'react-dom', 'antd', 'lodash',
+  'moment', 'classnames', 'codemirror'
+]
+
+module.exports = {
+  entry: {
+    'lib': vendors
+  },
+  output: {
+    path: path.join(basedir, 'app', 'ui'),
+    filename: '[name].js',
+    library: '[name]'
+  },
+  plugins: [
+    new webpack.optimize.UglifyJsPlugin({
+      sourceMap: true,
+      compress: {
+        warnings: false,
+        screw_ie8: true,
+        drop_console: true,
+        drop_debugger: true
+      }
+    }),
+    new webpack.DllPlugin({
+      path: path.join(basedir, 'tmp', 'manifest.json'),
+      name: '[name]',
+      context: basedir
+    }),
+    new webpack.BannerPlugin(`SwitchHosts! lib.js, ${moment().format('YYYY-MM-DD HH:mm:ss')}`)
+  ]
+}

+ 1 - 1
ui/app.jsx → ui/App.jsx

@@ -16,7 +16,7 @@ import Agent from './Agent'
 import { reg as events_reg } from './events/index'
 import notificationStyle from './misc/notificationStyle'
 
-import './app.less'
+import './App.less'
 
 export default class App extends React.Component {
   constructor (props) {

+ 0 - 0
ui/app.less → ui/App.less


+ 1 - 1
ui/index.jsx

@@ -7,7 +7,7 @@
 
 import React from 'react'
 import ReactDom from 'react-dom'
-import App from './app'
+import App from './App'
 
 ReactDom.render(
   <App/>

+ 8 - 4
webpack.config.js

@@ -12,12 +12,12 @@ const version = require('./app/version').version.join('.')
 
 module.exports = {
   entry: {
-    app: './ui/index.jsx',
-    vendor: ['react', 'antd']
+    app: './ui/index.jsx'
+    //, vendor: ['react', 'antd']
   },
   devtool: 'source-map',
   output: {
-    path: path.join(__dirname, 'app', 'static')
+    path: path.join(__dirname, 'app', 'ui')
     , filename: 'bundle.js'
     , sourceMapFilename: 'bundle.js.map'
   },
@@ -49,7 +49,7 @@ module.exports = {
         NODE_ENV: JSON.stringify('production')
       }
     })
-    , new webpack.optimize.CommonsChunkPlugin({name: 'vendor', filename: 'common.js'})
+    //, new webpack.optimize.CommonsChunkPlugin({name: 'vendor', filename: 'common.js'})
     , new webpack.optimize.UglifyJsPlugin({
       sourceMap: true,
       compress: {
@@ -60,6 +60,10 @@ module.exports = {
         comments: false
       }
     })
+    , new webpack.DllReferencePlugin({
+      context: __dirname,
+      manifest: require('./tmp/manifest.json')
+    })
     , new webpack.IgnorePlugin(new RegExp('^(electron|fs|path)$'))
     , new webpack.BannerPlugin(`SwitchHosts! [file] v${version}, ${moment().format('YYYY-MM-DD HH:mm:ss')}`)
   ]

部分文件因为文件数量过多而无法显示