diff --git a/build/webpack.base.conf.js b/build/webpack.base.conf.js index 141a0c7..7e8c4fc 100644 --- a/build/webpack.base.conf.js +++ b/build/webpack.base.conf.js @@ -3,7 +3,10 @@ const path = require('path') const utils = require('./utils') const config = require('../config') const { VueLoaderPlugin } = require('vue-loader') -const vueLoaderConfig = require('./vue-loader.conf') + +const os = require('os'); +const HappyPack = require('happypack'); +const happThreadPool = HappyPack.ThreadPool({size: os.cpus().length}); function resolve(dir) { return path.join(__dirname, '..', dir) @@ -21,6 +24,7 @@ const createLintingRule = () => ({ }) module.exports = { + cache: true, context: path.resolve(__dirname, '../'), entry:["babel-polyfill","./src/main.js"], output: { @@ -32,9 +36,11 @@ module.exports = { : config.dev.assetsPublicPath }, resolve: { + modules: [path.resolve(__dirname, '../node_modules')], extensions: ['.js', '.vue', '.json'], alias: { - '@': resolve('src') + '@': resolve('src'), + api: path.resolve(__dirname, '../src/api') } }, module: { @@ -43,16 +49,19 @@ module.exports = { { test: /\.vue$/, loader: 'vue-loader', - options: vueLoaderConfig + options: { + loaders: { + js: 'happypack/loader?id=js' // 将loader换成happypack + } + } }, { test: /\.js$/, - loader: 'babel-loader?cacheDirectory', + loader: ['happypack/loader?id=js'], // 将loader换成happypack include: [ - resolve('src'), - resolve('test'), - resolve('node_modules/webpack-dev-server/client') - ] + resolve('src') + ], // src是项目开发的目录 + exclude: [path.resolve('../node_modules')] // 不需要编译node_modules下的js }, { test: /\.svg$/, @@ -89,7 +98,15 @@ module.exports = { } ] }, - plugins: [new VueLoaderPlugin()], + plugins: [ + new VueLoaderPlugin(), + new HappyPack({ + id: 'js', + cache: true, + loaders: ['babel-loader?cacheDirectory=true'], + threadPool: happThreadPool + }) + ], node: { // prevent webpack from injecting useless setImmediate polyfill because Vue // source contains it (although only uses it if it's native). diff --git a/package.json b/package.json index 4ca462c..22e1eff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eladmin", - "version": "2.0.0", + "version": "2.1.0", "license": "Apache-2.0", "description": "eladmin 前端代码", "author": "jie ", @@ -50,12 +50,12 @@ "babel-plugin-syntax-jsx": "6.18.0", "babel-plugin-transform-runtime": "6.23.0", "babel-plugin-transform-vue-jsx": "3.7.0", + "babel-polyfill": "^6.26.0", "babel-preset-env": "1.7.0", "babel-preset-stage-2": "6.24.1", - "babel-polyfill": "^6.26.0", - "cross-env": "5.2.0", "chalk": "2.4.1", "copy-webpack-plugin": "4.5.2", + "cross-env": "5.2.0", "css-loader": "1.0.0", "eslint": "4.19.1", "eslint-friendly-formatter": "4.0.1", @@ -64,6 +64,7 @@ "eventsource-polyfill": "0.9.6", "file-loader": "1.1.11", "friendly-errors-webpack-plugin": "1.7.0", + "happypack": "^5.0.1", "html-webpack-plugin": "4.0.0-alpha", "mini-css-extract-plugin": "0.4.1", "node-notifier": "5.2.1", @@ -76,8 +77,8 @@ "postcss-url": "7.3.2", "rimraf": "2.6.2", "sass-loader": "7.0.3", - "script-loader": "0.7.2", "script-ext-html-webpack-plugin": "2.0.1", + "script-loader": "0.7.2", "semver": "5.5.0", "shelljs": "^0.8.3", "svg-sprite-loader": "3.8.0", diff --git a/src/layout/components/AppMain.vue b/src/layout/components/AppMain.vue index 8f9b6b8..cdcae97 100644 --- a/src/layout/components/AppMain.vue +++ b/src/layout/components/AppMain.vue @@ -1,6 +1,7 @@