-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
135 lines (132 loc) · 3.47 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { name } = require("./package.json");
module.exports = (env, argv) => {
const ENTRY_PATH = path.join(__dirname, "src/index.tsx");
const DIST_PATH = path.join(__dirname, "dist/");
let ASSETS_UMD = name
.replace("@tugraph/", "")
.split("-")
.join("_")
.toUpperCase();
console.log(ASSETS_UMD);
const plugins = env.analysis
? [
new MiniCssExtractPlugin(),
new BundleAnalyzerPlugin({
analyzerPort: Math.round(Math.random() * 100 + 8000)
})
]
: [new MiniCssExtractPlugin()];
return {
entry: {
index: ENTRY_PATH
},
mode: argv.mode,
module: {
rules: [
{
test: /\.js$/,
use: ["source-map-loader"],
enforce: "pre",
exclude: /node_modules/ //不包含 node_modules 中的JS文件
},
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
options: {
presets: ["@babel/env", "@babel/preset-react"],
plugins: [
["@babel/plugin-proposal-class-properties", { loose: true }],
["@babel/plugin-proposal-private-methods", { loose: true }],
[
"@babel/plugin-proposal-private-property-in-object",
{ loose: true }
],
["react-hot-loader/babel"]
]
}
},
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/,
options: {
compilerOptions: {
declaration: false
}
}
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
use: [
{
loader: "file-loader"
}
]
},
{
test: /\.less$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: "css-loader" // translates CSS into CommonJS
},
{
loader: "less-loader", // compiles Less to CSS
options: {
lessOptions: {
javascriptEnabled: true
}
}
}
],
sideEffects: true
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: ["file-loader"]
}
]
},
resolve: {
extensions: ["*", ".ts", ".tsx", ".js", ".jsx"],
fallback: {
fs: false //https://webpack.js.org/migrate/5/#clean-up-configuration
},
alias: {
"@": path.resolve(__dirname, "src"),
"@@": path.resolve(__dirname, "src/.umi")
}
},
// devtool: 'cheap-module-source-map',
output: {
library: ASSETS_UMD,
libraryTarget: "umd",
path: DIST_PATH,
publicPath: "./",
filename: "index.min.js"
},
plugins: plugins,
externals: {
lodash: "_",
react: "React",
"react-dom": "ReactDOM",
"@antv/graphin": "Graphin",
"@antv/g6": "G6",
"@antv/gi-sdk": "GISDK",
antd: "antd",
"@antv/g2plot": "G2Plot"
},
watch: Boolean(env.watch)
};
};