/
webpack.config.js
83 lines (72 loc) · 2.08 KB
/
webpack.config.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
var path = require('path');
var webpack = require('webpack');
// modules section is very similar for debug and release so
// the config is shared. In release we add eslint as a preLoader.
const modules = {
loaders: [
{
test : /\.js$/,
exclude: /node_modules/,
loader : 'babel-loader',
query : {
presets: ['es2015', 'stage-0'],
plugins: [
["babel-plugin-transform-builtin-extend", {
globals: ["Array"],
}]
],
}
},
],
};
// entry point doesn't vary by build
const entry = "./javascripts/dom.js";
// output is common to all builds
const output = {
libraryTarget: 'umd',
filename : "./dist/index.js"
};
// ===========================================================================
// debug builds a source map decorated, non minified version of the extension
// ===========================================================================
const debug = {
entry,
output,
module : modules,
devtool: "inline-source-map",
};
// ===========================================================================
// release builds a minified version of the extension
// ===========================================================================
const release = {
entry,
output,
module: Object.assign({}, modules, {
preLoaders: [
{test: /\.js$/, loader: "eslint-loader", exclude: /node_modules/}
],
}),
eslint: {
configFile : './.eslintrc',
failOnError: true
}
};
// ===========================================================================
// for test builds only. test enviroment must not have an entry point or
// output destination.
// ===========================================================================
const test = {
module: modules,
};
// get target from npm command used to start the build
const TARGET = process.env.npm_lifecycle_event;
// now build the required target ( for debug/test mode )
if (TARGET === 'build:dev') {
module.exports = debug;
}
if (TARGET === 'build:prod') {
module.exports = release;
}
if (TARGET === 'test') {
module.exports = test;
}