-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
57 lines (54 loc) · 1.68 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
const path = require("path");
const webpack = require("webpack");
const argv = require("yargs").argv;
const fs = require("fs");
// Shot package name will be used for prefix of filename
const fnPrefix = JSON.parse(fs.readFileSync(path.resolve(__dirname, "package.json"), "utf-8")).name.replace("grimoirejs", "grimoire");
// Copy task for optimization
class CopyPlugin{
constructor(copyFrom,copyTo){
this.copyFrom = copyFrom;
this.copyTo = copyTo;
}
apply(compiler){
compiler.plugin("after-emit",(compiler,callback)=>{
fs.createReadStream(this.copyFrom).pipe(fs.createWriteStream(this.copyTo));
callback();
});
}
}
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)=>{
let includeCore = true;
// if this package was preset including core or core package,
// Script for browser needs babel-polyfill
let polyfills = includeCore ? [true,false,true] : [false,false,false];
env = env || {};
let buildTasks = [];
let isDefault = !env.browser && !env.npm && !env.prod;
let skipIndex = false;
buildTasks.push(getBuildTask(`${fnPrefix}.js`, [],polyfills[0]));
return buildTasks;
};