This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwebpack.config.js
69 lines (65 loc) · 1.9 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
const path = require("path");
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const WebpackNotifierPlugin = require("webpack-notifier");
const package = require("./package.json");
const umdName = package["umdName"] || package["name"];
const externals = package["externalsForWebpack"] || [];
const targetFileName = path.basename(package["main"]);
const targetDirName = path.dirname(package["main"]);
var PROD = JSON.parse(process.env.PROD || false);
module.exports = {
entry: "./src/index.ts",
mode: "none",
devtool: "source-map",
plugins: [
new WebpackNotifierPlugin({
title: targetFileName,
alwaysNotify: true
})
],
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/
}
]
},
resolve: {
extensions: [ ".ts" ]
},
output: {
filename: targetFileName,
path: path.resolve(__dirname, targetDirName),
library: umdName,
libraryTarget: "umd",
// Workaround for Webpack 4. See https://github.com/webpack/webpack/issues/6522#issuecomment-371120689
globalObject: "typeof self !== \"undefined\" ? self : this"
},
externals: externals
};
if (PROD) {
// https://webpack.js.org/concepts/mode/#mode-production
module.exports.mode = "production";
module.exports.optimization = {
minimizer: [
new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true,
// We actually only want to keep function arguments (for console
// completion), but all the minifiers I've found group this with
// mangling internal variable names. :-/
// So we take the size hit. Apps will have to minify their final
// builds if they want to save more on size.
mangle: false
},
}),
]
};
module.exports.plugins.push(
new webpack.NoEmitOnErrorsPlugin()
);
}