diff --git a/lib/babel/createBabelConfig.js b/lib/babel/createBabelConfig.js index 471d598..1ba7039 100644 --- a/lib/babel/createBabelConfig.js +++ b/lib/babel/createBabelConfig.js @@ -22,7 +22,7 @@ module.exports = function createBabelConfig (context, isWebpack) { plugins: [ [require.resolve('babel-plugin-module-alias'), context.userConfig.aliases], [require.resolve('babel-plugin-transform-decorators-legacy')], - [require.resolve('babel-plugin-transform-runtime')], + // [require.resolve('babel-plugin-transform-runtime')], [require.resolve('babel-plugin-glob-imports')] ], env: { diff --git a/lib/loaders/babel.js b/lib/loaders/babel.js index 14bd2bd..420683c 100644 --- a/lib/loaders/babel.js +++ b/lib/loaders/babel.js @@ -1,4 +1,5 @@ 'use strict'; +const path = require('path'); module.exports = [ (context) => { @@ -10,6 +11,7 @@ module.exports = [ test: /\.jsx?$/, loader: 'babel', exclude: /node_modules/, + include: path.join(context.projectDir, 'src'), query: babelConfig, happy: {id: 'js'} } diff --git a/lib/loaders/fonts.js b/lib/loaders/fonts.js index 0f5f9ea..a9bff85 100644 --- a/lib/loaders/fonts.js +++ b/lib/loaders/fonts.js @@ -8,7 +8,8 @@ module.exports = [ name: 'fonts/[name]-[hash].[ext]', limit: 10000, mimetype: 'application/font-woff' - } + }, + // happy: {id: 'woff'} }, { test: /\.woff2(\?.*)?$/, @@ -17,7 +18,8 @@ module.exports = [ name: 'fonts/[name]-[hash].[ext]', limit: 10000, mimetype: 'application/font-woff2' - } + }, + // happy: {id: 'woff2'} }, { test: /\.ttf(\?.*)?$/, @@ -26,14 +28,16 @@ module.exports = [ name: 'fonts/[name]-[hash].[ext]', limit: 10000, mimetype: 'application/octet-stream' - } + }, + // happy: {id: 'ttf'} }, { test: /\.eot(\?.*)?$/, loader: 'file', query: { name: 'fonts/[name]-[hash].[ext]' - } + }, + // happy: {id: 'eot'} }, { test: /\.svg(\?.*)?$/, @@ -42,6 +46,7 @@ module.exports = [ name: 'fonts/[name]-[hash].[ext]', limit: 10000, mimetype: 'image/svg+xml' - } + }, + // happy: {id: 'svg'} } ]; diff --git a/lib/loaders/img.js b/lib/loaders/img.js index a8e2a0c..735c1fa 100644 --- a/lib/loaders/img.js +++ b/lib/loaders/img.js @@ -6,6 +6,7 @@ module.exports = [ loader: 'url', query: { limit: 8192 - } + }, + // happy: {id: 'img'} } ]; diff --git a/lib/webpack/webpack.dev.config.js b/lib/webpack/webpack.dev.config.js index b0de458..3a6f1f7 100644 --- a/lib/webpack/webpack.dev.config.js +++ b/lib/webpack/webpack.dev.config.js @@ -6,7 +6,8 @@ const path = require('path'); const webpack = require('webpack'); const getLoaders = require('./getLoaders'); const HappyPack = require('happypack'); -var happyThreadPool = HappyPack.ThreadPool({ size: 5 }); +const os = require('os'); +var happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length }); const allLoaders = Object.assign(requireDir('../loaders'), requireDir('../loaders/dev')); @@ -18,6 +19,16 @@ const defaultDefine = { } }; +function makeHappy(loaders) { + return loaders + .filter(l => l.happy) + .map(l => new HappyPack({ + id: l.happy.id, + threadPool: happyThreadPool, + cache: true + })) +} + // https://gist.github.com/sokra/27b24881210b56bbaff7 // http://www.2ality.com/2015/12/webpack-tree-shaking.html module.exports = function devConfig (context) { @@ -25,14 +36,15 @@ module.exports = function devConfig (context) { const definitions = Object.assign({}, defaultDefine, context.userConfig.define); return { - devtool: 'inline-source-map', + // cache: true, + // devtool: 'inline-source-map', entry: [ require.resolve('webpack-hot-middleware/client'), path.join(context.projectDir, 'src/index') ], output: { path: path.join(context.projectDir, 'dist'), - filename: '[name]-[hash].js', + filename: '[name].js', publicPath: '/' }, plugins: [ @@ -42,21 +54,13 @@ module.exports = function devConfig (context) { new HtmlWebpackPlugin({ title: context.pkg.name, template: context.indexPath - }), - new HappyPack({ - id: 'js', - threadPool: happyThreadPool, - cache: true - }), - new HappyPack({ - id: 'css', - threadPool: happyThreadPool, - cache: true }) - ], + ] + .concat(...makeHappy(loaders)) + , resolve: { modules: [path.join(context.projectDir, 'src'), 'node_modules'], - extensions: ['', '.js', '.json'] + extensions: ['.js'] }, resolveLoader: { modules: [path.join(context.rootDir, 'node_modules'), path.join(context.projectDir, 'node_modules')]