generated from caicloud/common-template-project
-
Notifications
You must be signed in to change notification settings - Fork 14
/
webpack.module.config.js
82 lines (81 loc) · 1.9 KB
/
webpack.module.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
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const {
ModulePlugin,
ExternalsPlugin,
} = require('@caicloud/modularize/webpack');
const {
m12n: { moduleName, port },
webpack: { publicPath },
} = require('./package.json');
module.exports = [{
devServer: {
contentBase: false,
hot: true,
port,
host: 'localhost',
public: `localhost:${port}`,
historyApiFallback: {
// 在 webpack dev server 下模拟 module-manifest.html 接口
rewrites: [
{
from: /module-manifest\.html/,
to: path.join(publicPath, 'module-manifest.html'),
},
],
},
},
devtool: 'sourcemap',
entry: {
[moduleName]: path.join(__dirname, './client/module.js'),
},
output: {
publicPath,
filename: `${moduleName}~[name].js`,
chunkFilename: `${moduleName}~[id]~[chunkhash].js`,
jsonpFunction: `webpackJsonp_${moduleName}`,
},
module: {
rules: [
{
test: /\.js|jsx|ts|tsx$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/typescript',
'@babel/preset-react',
'@babel/preset-env',
],
},
},
},
{
test: /\.m\.less$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: true,
},
},
{
loader: 'less-loader',
},
],
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
plugins: [
new CleanWebpackPlugin(path.join(__dirname, 'dist')),
new ModulePlugin({ moduleName, register: false }),
new ExternalsPlugin(),
],
}, ...(process.env.NODE_ENV === 'production' ? [require('./webpack.node.config')] : [])];