-
Notifications
You must be signed in to change notification settings - Fork 49
/
webpack.config.dev.site.js
180 lines (175 loc) · 4.83 KB
/
webpack.config.dev.site.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* eslint-disable no-console */
const webpack = require('webpack');
const path = require('path');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { parseDir, getReplParams } = require('./tools/helps');
// import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer';
console.log('-----------------------------------------------------');
console.log('开发环境默认关闭demo中嵌入的iframe页面的打包,如果需要调试iframe demo, 运行npm run open:site -- --iframe=true来开启');
console.log('-----------------------------------------------------\n');
// demo中嵌入的iframe页面打包开关,默认关闭,通过REPL运行npm run open:site -- --iframe=true来开启
let iframe = false;
let replIframe = getReplParams('iframe');
if (replIframe) {
iframe = JSON.parse(replIframe[0]);
}
const demoPath = './site/docs/demoPage/';
const getHtmlWebpackPlugin = () => {
if (iframe) {
const demoNameArr = [];
parseDir(demoPath, demoNameArr);
const htmlWebpackPlugin = demoNameArr
.filter((name) => {
return name.slice(-3) === '.js';
})
.map((name) => {
const demoName = name.slice(0, -3);
return new HtmlWebpackPlugin({
filename: 'demo/' + demoName + '.html',
template: path.join(__dirname, demoPath + 'demo.html'),
chunks: [demoName]
});
});
return htmlWebpackPlugin;
} else {
return [];
}
};
const getDemoEntries = () => {
const entries = {};
if (iframe) {
const demoNameArr = [];
parseDir(demoPath, demoNameArr);
const arr = demoNameArr.filter((name) => {
return name.slice(-3) === '.js';
}
);
for (let each of arr) {
entries[each.slice(0, -3)] = [demoPath + each];
}
}
return entries;
};
module.exports = {
mode: 'development',
// more info:https://webpack.github.io/docs/build-performance.html#sourcemaps
// and https://webpack.github.io/docs/configuration.html#devtool
devtool: 'cheap-module-source-map',
entry: Object.assign({},
{
site: [
'webpack-dev-server/client?http://localhost:5000',
'webpack/hot/only-dev-server',
'react-hot-loader/patch',
'./site/index'
],
},
getDemoEntries()
),
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js'
},
plugins: [
// new BundleAnalyzerPlugin({
// analyzerMode: 'static'
// }),
new webpack.HotModuleReplacementPlugin(),
new CaseSensitivePathsPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'site/index.html'),
chunks: ['site'],
favicon: 'site/assets/favicon.ico'
})].concat(getHtmlWebpackPlugin()),
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
node: {
fs: 'empty'
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
},
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.less$/,
use: [{
loader: 'style-loader'
}, {
loader: 'css-loader'
}, {
loader: 'less-loader',
options: {
javascriptEnabled: true
},
}]
},
{
test: /\.css$/,
use: [{
loader: 'style-loader'
}, {
loader: 'css-loader'
}]
},
{
test: /\.svg$/,
oneOf: [
// oneOf uses the first matching rule. So for your use case put the
// resourceQuery: /module/ into the first entry and no resourceQuery
// at all into the second. – Daniel Jul 5 '17 at 15:52
{
test: /static[/\\]icons/,
use: [
"babel-loader",
{
loader: "react-svg-loader",
options: {
svgo: {
plugins: [
{ removeDimensions: true },
{
addAttributesToSVGElement: {
attributes: [
'fill="currentColor"',
'height="16"',
'width="16"'
]
},
}, {
removeAttrs: {
attrs: 'path:fill'
}
}]
}
}
}]
},
{
use: 'file-loader'
},
],
},
{
test: /\.(ttf|eot|woff|woff2)(\?.+)?$/,
loader: 'file-loader',
},
{
test: /\.(jpe?g|png|gif)(\?.+)?$/,
loader: 'file-loader'
},
{
test: /\.md$/,
loader: 'raw-loader'
}
]
}
};