-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.server.js
More file actions
69 lines (68 loc) · 1.84 KB
/
webpack.server.js
File metadata and controls
69 lines (68 loc) · 1.84 KB
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 MiniCssExtractPlugin = require('mini-css-extract-plugin')
const path = require('path')
module.exports = {
entry: { server: './src/server/index.tsx' },
target: 'node',
mode: process.env.NODE_ENV || 'production',
output: {
filename: 'serverRender.js',
path: path.resolve(__dirname, 'dist/server'),
clean: true,
library: {
name: 'ssr',
type: 'commonjs'
}
},
resolve: {
extensions: ['.tsx', '.ts', '...'],
alias: {
components: path.resolve(__dirname, 'src/components/'),
pages: path.resolve(__dirname, 'src/pages/'),
assets: path.resolve(__dirname, 'src/assets/'),
utils: path.resolve(__dirname, 'src/utils/'),
types: path.resolve(__dirname, 'src/types/'),
_constants: path.resolve(__dirname, 'src/constants'),
api: path.resolve(__dirname, 'src/api/'),
public: path.resolve(__dirname, 'src/public/')
}
},
// TODO 方便调试,可以仅在 dev 环境下开启
// optimization: {
// minimize: false
// },
module: {
rules: [
{
test: /\.(ts|tsx)$/i,
// use: ['ts-loader']
// TODO ts compile fail 不阻塞 webpack 编译完毕
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true
}
}
] // WILL DISABLE TYPESCRIPT ERRORS
},
{
test: /\.css$/i, // 处理 css 文件,先安装依赖,再配置
use: [
{
loader: MiniCssExtractPlugin.loader, // 将 css 抽离到文件中,通过 link 标签将文件引入 html 中
options: {
emit: false
}
},
'css-loader'
]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[id].[contenthash].css'
})
]
}