forked from mzgoddard/jest-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
87 lines (73 loc) · 2.63 KB
/
webpack.config.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var {join, resolve} = require('path');
// var HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
var webpack = require('webpack');
var webpackIf = require('webpack-if');
var ProvidePlugin = webpack.ProvidePlugin;
var root = process.cwd();
var startsWith = webpackIf.op((pred, value) => pred.startsWith(String(value)));
var nodeEnv = () => process.env.NODE_ENV;
var webpackVersion = () => require('webpack/package.json').version;
var isEnv = webpackIf.is(nodeEnv);
var isWebpackVersion = startsWith(webpackVersion);
var ifProd = webpackIf.ifElse(isEnv("production"));
var ifWebpack1 = webpackIf.ifElse(isWebpackVersion(1));
module.exports = webpackIf({
// context: Content for entries.
context: root,
entry: {
'jest-webpack': './src/jest-webpack.js',
},
output: {
path: join(__dirname, 'webpack-1'),
filename: '[name].js',
libraryTarget: 'commonjs2',
// devtoolModuleFilenameTemplate sets the stored path in the source maps
// sources array. jest will use this to read the original file.
devtoolModuleFilenameTemplate: join(__dirname, '[resource-path]'),
},
// devtool: Enable for source maps. Module means lines of the loader output,
// in this case the es5 output from babel.
devtool: 'module-source-map',
externals: function(context, request, callback) {
if (request.indexOf('!') === -1 && /^\w/.test(request)) {
return callback(null, request, 'commonjs2');
}
callback(null);
},
target: 'node',
// node: Options for automatic shims for node functionality.
node: {
// __dirname: Set false to disable automatic __dirname shim.
__dirname: false,
__filename: false,
process: false,
},
// module: module configuration.
module: {
// rules: Loaders automatically applied based on test, include, and
// exclude options.
[ifWebpack1('loaders', 'rules')]: [
// Apply babel-loader to any js file not under node_modules.
{
test: /\.jsx?$/,
exclude: [resolve(root, 'node_modules')],
loader: ifWebpack1(
'babel-loader?{presets:[["env",{targets:{node:4}}]]}',
'babel-loader',
),
// options: Babel-loader configuration.
options: ifWebpack1(null, () => ({
// babel.presets: Plugin presets babel loader will add on top of those
// specified in babelrc.
'presets': [['env', {targets: {node: 4}}]],
})),
},
],
},
// plugins: webpack plugins.
plugins: [
// A webpack cache plugin. A cache is written to the file system and reused
// when possible during later runs for faster builds.
// new HardSourceWebpackPlugin(),
],
});