-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwebpack.config.js
85 lines (81 loc) · 2.14 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
const path = require('path');
const webpack = require('webpack');
const package = require('./package.json');
const Visualizer = require('webpack-visualizer-plugin');
const modName = 'tcb';
// 合并声明文件plugin
// function DtsBundlePlugin() { }
// DtsBundlePlugin.prototype.apply = function (compiler) {
// compiler.plugin('done', function () {
// if (process.env.NODE_ENV === 'e2e') {
// return;
// }
// const dts = require('dts-bundle');
// dts.bundle({
// name: modName,
// main: 'dist/index.d.ts',
// out: path.join(__dirname, `tcbjs/${package.version}/${modName}.d.ts`),
// outputAsModuleFolder: true
// });
// });
// };
module.exports = {
mode: 'production',
// mode: 'development',
// regenerator-runtime/runtime是Generator的polyfill
// 解决async/await被babel转成generator后的兼容问题
entry: [
'regenerator-runtime/runtime', './dist/index.js'
],
devtool: false,
output: {
path: path.resolve(__dirname, 'tcbjs'),
filename: process.env.NODE_ENV === 'e2e' ? 'e2e/tcb.js' : `${package.version}/${modName}.js`,
library: modName,
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: 'typeof window !== "undefined"?window:this'
},
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.js?$/,
loader: 'babel-loader',
exclude: [/node_modules/],
options: {
presets: [
[
'@babel/preset-env',
{
modules: 'commonjs',
// useBuiltIns: 'usage',
corejs: 3
}
]
]
}
},
{
test: /package\.json$/,
loader: 'package-json-cleanup-loader',
options: {
only: ['version']
}
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.END_POINT': JSON.stringify(process.env.END_POINT)
}),
new Visualizer({
filename: './statistics.html'
}),
// new DtsBundlePlugin()
],
// externals: { crypto: 'crypto'}
};