UNPKG

2.02 kBJavaScriptView Raw
1'use strict';
2
3var path = require('path');
4var HappyPack = require('happypack');
5
6exports.config = function (options, cwd) {
7 var defaultQuery = {};
8 if(this.webpack.version && this.webpack.version >= 2) {
9 defaultQuery = {
10 cacheDirectory: true,
11 presets: [
12 ['es2015', {loose: true, modules: false}],
13 'es2017',
14 'stage-0'
15 ],
16 plugins: []
17 }
18 } else {
19 defaultQuery = {
20 cacheDirectory: true,
21 presets: [
22 ['es2015', {loose: true, modules: 'commonjs'}],
23 'es2017',
24 'stage-0'
25 ],
26 plugins: ['transform-es2015-modules-simple-commonjs']
27 }
28 }
29
30 var baseConfig = this.config,
31 testReg = options.test ? options.test : /\.(js|jsx)$/,
32 exclude = options.exclude ? options.exclude : /node_modules/,
33 query = options.modifyQuery ? options.modifyQuery(defaultQuery) : defaultQuery,
34 happyPackConfig = {
35 loaders: [
36 {
37 loader: 'babel-loader',
38 test: testReg,
39 exclude: exclude,
40 query: query
41 }
42 ],
43 threads: 4,
44 verbose: false,
45 cacheContext: {
46 env: process.env.NODE_ENV
47 },
48 tempDir: path.join(__dirname, '../happypack'),
49 cachePath: path.join(__dirname, '../happypack/cache--[id].json')
50 };
51
52 happyPackConfig = options.modifyHappypack ? options.modifyHappypack(happyPackConfig) : happyPackConfig;
53
54 extend(true, baseConfig, {
55 module: {
56 loaders: baseConfig.module.loaders.concat([{
57 test: testReg,
58 exclude: exclude,
59 loader: 'happypack/loader'
60 }])
61 },
62 plugins: baseConfig.plugins.concat([
63 new HappyPack(happyPackConfig)
64 ])
65 });
66};