Skip to content

Commit

Permalink
[+] add happypack
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed Jan 13, 2018
1 parent 081201d commit 9828f1b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
"eslint-plugin-vue": "^2.1.0",
"filemanager-webpack-plugin": "^1.0.16",
"glob": "^7.1.2",
"happypack": "^4.0.0",
"lerna": "^2.5.1",
"os": "^0.1.1",
"postcss-loader": "^2.0.10",
"postcss-plugin-px2rem": "^0.7.0",
"postcss-plugin-weex": "^0.1.1",
"postcss-px2rem": "^0.3.0",
Expand Down
12 changes: 12 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
plugins: [
require('postcss-plugin-weex')(),
require('autoprefixer')({
browsers: ['> 0.1%', 'ios >= 8', 'not ie < 12']
}),
require('postcss-plugin-px2rem')({
rootValue: 75,
minPixelValue: 1.01
})
]
};
48 changes: 32 additions & 16 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const glob = require('glob');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

const os = require('os');
const HappyPack = require('happypack');
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
HappyPack.SERIALIZABLE_OPTIONS = HappyPack.SERIALIZABLE_OPTIONS.concat(['postcss']);

console.log('Building..., Please wait a moment.');

const getEntry = dir => {
Expand Down Expand Up @@ -48,6 +53,24 @@ const plugins = [
new CleanWebpackPlugin(['build'], {
verbose: true
}),
new webpack.optimize.CommonsChunkPlugin({
async: 'shared-module',
minChunks: (module, count) => (
count >= 2
)
}),
new HappyPack({
id: 'babel',
verbose: true,
loaders: ['babel-loader?cacheDirectory=true'],
threadPool: happyThreadPool
}),
new HappyPack({
id: 'css',
verbose: true,
loaders: ['postcss-loader'],
threadPool: happyThreadPool
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
Expand All @@ -65,6 +88,7 @@ const needClean = process.argv.indexOf('--watch') > -1;
needClean && plugins.shift();

const getBaseConfig = () => ({
cache: true,
devtool: '#source-map',
entry,
context: __dirname,
Expand All @@ -84,15 +108,14 @@ const getBaseConfig = () => ({
module: {
rules: [{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
}
}
use: 'happypack/loader?id=babel',
exclude: /node_modules/
}, {
test: /\.vue(\?[^?]+)?$/,
use: []
}, {
test: /\.css$/,
use: 'happypack/loader?id=css'
}]
},
plugins,
Expand All @@ -111,16 +134,9 @@ webCfg.module.rules[1].use.push({
loader: 'vue-loader',
options: {
optimizeSSR: false,
postcss: [
require('postcss-plugin-weex')(),
require('autoprefixer')({
browsers: ['> 0.1%', 'ios >= 8', 'not ie < 12']
}),
require('postcss-plugin-px2rem')({
rootValue: 75,
minPixelValue: 1.01
})
],
loaders: {
js: 'happypack/loader?id=babel'
},
compilerModules: [
{
postTransformNode: el => {
Expand Down

0 comments on commit 9828f1b

Please sign in to comment.