-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebpack.dev.config.js
115 lines (113 loc) · 3.31 KB
/
webpack.dev.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
const { resolve } = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const manifest = require('./dll/vendors-manifest.json');
module.exports = () => {
return {
entry: {
index: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8000',
'webpack/hot/only-dev-server',
'./src/index.dev.js',
],
},
output: {
path: resolve(__dirname, 'dist'),
filename: '[name].js',
publicPath: '/', // 同output的publicPath
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['react-hot-loader/webpack', 'babel-loader', 'eslint-loader'],
},
{
test: /favicon.(png|ico)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]',
},
},
],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
{
test: /\.less$/,
use: ['style-loader', 'css-loader?modules&localIdentName=[name]__[local]___[hash:base64:5]', 'less-loader', 'postcss-loader'],
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader?modules', 'scss-loader', 'postcss-loader'],
},
{
test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
exclude: /favicon.png$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
},
},
],
},
],
},
// devtool: 'eval',
// resolve: {
// alias: {
// react: 'preact-compat',
// 'react-dom': 'preact-compat',
// 'preact-compat': 'preact-compat/dist/preact-compat',
// },
// },
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"',
}),
new CopyWebpackPlugin([{ from: './dll/vendors.dll.js', to: 'dll.js' }]),
new HtmlWebpackPlugin({ template: './public/index.dev.html' }),
// new webpack.HotModuleReplacementPlugin(), // enable HMR globally
new webpack.NoEmitOnErrorsPlugin(), // 遇到错误继续
new webpack.NamedModulesPlugin(), // prints more readable module names
new webpack.DllReferencePlugin({ context: __dirname, manifest }),
],
devServer: {
port: 8000,
host: '0.0.0.0',
historyApiFallback: true,
disableHostCheck: true,
contentBase: '/', // 配置服务器目录
publicPath: '/', // 同output的publicPath
proxy: {
'/api': {
target: 'http://api.zhuishushenqi.com/',
changeOrigin: true,
pathRewrite: { '^/api': '' },
},
'/chapter': {
target: 'http://chapter2.zhuishushenqi.com/',
changeOrigin: true,
pathRewrite: { '^/api': '' },
},
'/agent': {
target: 'http://statics.zhuishushenqi.com/',
changeOrigin: true,
pathRewrite: { '^/api': '' },
},
},
},
// performance: {
// hints: options.dev ? false : 'warning',
// },
};
};