This repository has been archived by the owner on Dec 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
107 lines (88 loc) · 2.25 KB
/
webpack.common.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
98
99
100
101
102
103
104
105
106
107
const webpack = require("webpack");
const path = require("path");
//#region for config
const pkg = require('./package.json');
const productName = 'MagicalParser'; /// the global name for your integrated module
const {mode} = require('./package.json');
//#region banner
const date = new Date();
const banner = `
${pkg.name} v${pkg.version} ${date}
by ${pkg.author instanceof Object ? pkg.author.name + ' ' + pkg.author.email : pkg.author}
${ pkg.homepage || ''}
Copyright: ${ date.getFullYear()} NTNU;
License: ${ pkg.license}
Build: [hash]
`;
//#endregion
//#endregion
//#region
function getFileExtension(libraryTarget) {
let fileExtention = "";
switch (libraryTarget) {
case "commonjs2":
fileExtention = "common";
break;
case 'umd':
fileExtention = '';
break;
default:
fileExtention = libraryTarget;
break;
}
return fileExtention;
}
function getOutput(options) {
var fileExtention = getFileExtension(options.libraryTarget);
if (options.libraryTarget === 'umd') {
return {
path: path.resolve(__dirname, "lib"),
filename: productName + ".js",
library: productName,
libraryTarget: 'umd'
};
}
else {
return {
path: path.resolve(__dirname, "lib"),
filename: productName + '.' + fileExtention + '.js',
libraryExport: 'default',
libraryTarget: options.libraryTarget,
umdNamedDefine: true,
globalObject: `(typeof self !== 'undefined' ? self : this)`
};
}
}
function createConfig(options) {
var entry = "./build/index.js";
var output = getOutput(options);
var babelOptions = require('./babel.config');
return {
mode,
entry,
output,
devtool: 'source-map',
watch: false,
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: [
{
loader: "babel-loader",
options: babelOptions,
},
]
}
]
},
plugins: [
new webpack.BannerPlugin({ banner }),
]
};
}
//#endregion
module.exports = {
createConfig
}