-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
121 lines (114 loc) · 3.95 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
const path = require('path')
const webpack = require('webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin
const hfappVersion = require('./package.json').dependencies[
'@hai-platform/studio-pages'
]
// const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
console.info('inject user webpack, process.env.HF_ENV:', process.env.HF_FE_ENV)
const buildApp = process.env.BUILD_APP || 'jupyter'
function getUserName() {
const child_process = require('child_process')
let uname = (child_process.execSync(`whoami`) + '').replace(/[\n\s]/g, '')
return uname
}
const additionalPlugins = []
module.exports = {
resolve: {
extensions: ['.tsx', '.ts', '.js', '.svg'],
alias: {
'@': path.resolve(__dirname, 'src'),
'@components': path.resolve('src/components'),
'@utils': path.resolve('src/utils')
}
},
// entry: {
// 'editor.worker': 'monaco-editor/esm/vs/editor/editor.worker.js'
// },
optimization: {
usedExports: true
},
plugins: [
// hint: 2022.07.09 补充:用了这个插件之后,反而产物更大了
// new MonacoWebpackPlugin({
// languages: [],
// features: []
// }),
new webpack.NormalModuleReplacementPlugin(
/.\/iconSvgPaths/,
`${path.resolve(__dirname, 'src/svgReplace/iconSvgReplacePath.js')}`
),
// 实际上 jupyterlab builder 本身并没有使用这个插件,所以我们可以放心使用
new webpack.EnvironmentPlugin({
DEBUG_USER_NAME: getUserName(),
BLUEPRINT_NAMESPACE: 'hai-ui',
HF_FE_ENV: process.env.HF_FE_ENV || 'production',
REACT_APP_BLUEPRINT_NAMESPACE: 'hai-ui',
REACT_APP_HFUI_NAMESPACE: 'hai-ui',
HFAPP_VERSION: hfappVersion
}),
new BundleAnalyzerPlugin({
// analyzerPort: 3004
analyzerMode: 'static'
})
],
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
// HINT: jupyterlab 自身只有 js 的引入情况,这里增加 ts/tsx
issuer: /\.(ts|tsx)$/,
use: {
loader: 'raw-loader'
}
},
{
test: /\.s[ac]ss$/i,
use: [
// 将 JS 字符串生成为 style 节点
'style-loader',
// 将 CSS 转化成 CommonJS 模块
'css-loader',
// 将 Sass 编译成 CSS
{
loader: 'sass-loader',
options: {
sassOptions: loaderContext => {
return {
functions: require('./sass-custom-functions.js')
}
}
}
}
]
},
{
test: /\.less$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader' // translates CSS into CommonJS
},
{
loader: 'less-loader', // compiles Less to CSS
options: {
lessOptions: {
// If you are using less-loader@5 please spread the lessOptions to options directly
javascriptEnabled: true
}
}
}
]
},
...additionalPlugins,
]
}
}