Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
geowarin committed Jul 1, 2016
1 parent 8d6b4ba commit c199add
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/babel/createBabelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 2 additions & 0 deletions lib/loaders/babel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const path = require('path');

module.exports = [
(context) => {
Expand All @@ -10,6 +11,7 @@ module.exports = [
test: /\.jsx?$/,
loader: 'babel',
exclude: /node_modules/,
include: path.join(context.projectDir, 'src'),
query: babelConfig,
happy: {id: 'js'}
}
Expand Down
15 changes: 10 additions & 5 deletions lib/loaders/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = [
name: 'fonts/[name]-[hash].[ext]',
limit: 10000,
mimetype: 'application/font-woff'
}
},
// happy: {id: 'woff'}
},
{
test: /\.woff2(\?.*)?$/,
Expand All @@ -17,7 +18,8 @@ module.exports = [
name: 'fonts/[name]-[hash].[ext]',
limit: 10000,
mimetype: 'application/font-woff2'
}
},
// happy: {id: 'woff2'}
},
{
test: /\.ttf(\?.*)?$/,
Expand All @@ -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(\?.*)?$/,
Expand All @@ -42,6 +46,7 @@ module.exports = [
name: 'fonts/[name]-[hash].[ext]',
limit: 10000,
mimetype: 'image/svg+xml'
}
},
// happy: {id: 'svg'}
}
];
3 changes: 2 additions & 1 deletion lib/loaders/img.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = [
loader: 'url',
query: {
limit: 8192
}
},
// happy: {id: 'img'}
}
];
34 changes: 19 additions & 15 deletions lib/webpack/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand All @@ -18,21 +19,32 @@ 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) {
const loaders = getLoaders(allLoaders, 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: [
Expand All @@ -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')]
Expand Down

0 comments on commit c199add

Please sign in to comment.