-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.js
97 lines (88 loc) · 2.32 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const webpack = require("webpack");
const createVariants = require('parallel-webpack').createVariants;
const path = require("path");
const pkg = require('./package.json');
const mode = 'production';
const timeStamp = new Date().toLocaleTimeString();
const date = new Date();
const banner = `
${pkg.name} v${pkg.version} ${date}
by ${pkg.author.name} ${pkg.author.email}
${pkg.homepage}
Copyright: 2019 NTNU
License: ${pkg.license}
Build: [hash]
`;
let umdConfig = {
mode: mode,
entry: "./build/merge.js",
output: {
path: path.resolve(__dirname, "lib"),
filename: "tex2max.js",
library: "tex2max",
libraryTarget: 'umd',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader"
}
}
]
},
plugins: [
new webpack.BannerPlugin({banner: banner}),
]
};
function getFileExtension(libraryTarget) {
let fileExtention = "";
switch (libraryTarget) {
case "commonjs2":
fileExtention = "common";
break;
default :
fileExtention = libraryTarget;
break;
}
return fileExtention;
}
function createConfig(options) {
let plugins = [
new webpack.BannerPlugin({banner: banner}),
];
let fileExtention = getFileExtension(options.libraryTarget);
return {
mode: mode,
entry: './src/index.js',
output: {
path: path.resolve(__dirname, "lib"),
filename: 'tex2max.' +
fileExtention
+ '.js',
libraryExport: 'default',
libraryTarget: options.libraryTarget,
umdNamedDefine: true,
globalObject: `(typeof self !== 'undefined' ? self : this)`
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader"
}
}
]
},
plugins: plugins
};
}
let variants = {
libraryTarget: ['commonjs2', 'amd']
};
let variantsConfig = createVariants(variants, createConfig);
module.exports = [...variantsConfig, umdConfig];