-
Notifications
You must be signed in to change notification settings - Fork 111
/
webpack.config.js
143 lines (138 loc) · 3.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
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
136
137
138
139
140
141
142
143
/* 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 webpack = require('webpack');
module.exports = (env, argv) => {
const ASSETS_PATH = path.join(__dirname, env.path);
const ENTRY_PATH = path.join(ASSETS_PATH, 'src/index.tsx');
const DIST_PATH = path.join(ASSETS_PATH, 'dist/');
let ASSETS_UMD = env.path.replace('/packages/', '').split('-').join('_').toUpperCase();
if (ASSETS_UMD === 'GI_SDK') {
ASSETS_UMD = 'GISDK';
}
console.log(ASSETS_UMD);
const plugins = env.analysis
? [
new MiniCssExtractPlugin(),
new BundleAnalyzerPlugin({
analyzerPort: Math.round(Math.random() * 100 + 8000),
}),
]
: [
new MiniCssExtractPlugin(),
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
];
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-transform-class-properties', { loose: true }],
['@babel/plugin-transform-private-methods', { loose: true }],
['@babel/plugin-transform-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
crypto: require.resolve('crypto-browserify'),
constants: require.resolve('constants-browserify'),
// // crypto: false,
// // constants: false,
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer'),
// buffer: require.resolve('buffer-browserify'),
},
},
// 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),
};
};