-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·49 lines (45 loc) · 1.53 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
const path = require("path");
const webpack = require("webpack");
const argv = require("yargs").argv;
const fs = require("fs");
const fnPrefix = JSON.parse(fs.readFileSync(path.resolve(__dirname, "package.json"), "utf-8")).name.replace("grimoirejs", "grimoire");
const getBuildTask = (fileName, plugins, needPolyfill) => {
return {
cache: true,
entry: needPolyfill ? ['babel-polyfill', path.resolve(__dirname, "src/index.ts")] : path.resolve(__dirname, "src/index.ts"),
output: {
path: __dirname,
filename: "/register/" + fileName,
libraryTarget: "umd"
},
module: {
loaders: [{
test: /\.ts$/,
exclude: /node_modules/,
loader: "babel-loader?presets[]=es2015,presets[]=stage-2!ts-loader"
}]
},
resolve: {
extensions: ['.ts', '.js']
},
plugins: plugins,
devtool: 'source-map'
}
};
module.exports = (env) => {
env = env || {};
const buildTasks = [getBuildTask(fnPrefix + ".js", [])]
if (env.prod) {
buildTasks.push(getBuildTask("index.js", [])); // for npm registeirng
buildTasks.push(getBuildTask(fnPrefix + ".min.js", [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin()
]));
}
return buildTasks;
};