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