-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.dev.js
More file actions
122 lines (117 loc) · 3.59 KB
/
webpack.config.dev.js
File metadata and controls
122 lines (117 loc) · 3.59 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
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
'use strict';
const path = require('path');
const yargs = require('yargs');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
const argv = yargs.argv;
const port = argv.port || '8080';
// 判断当前运行环境是开发模式还是生产模式
console.log("process.env.NODE_ENV =>>>> ", process.env.NODE_ENV);
const nodeEnv = process.env.NODE_ENV || 'development';
const isPro = nodeEnv === 'production';
const plugins = [
new webpack.DefinePlugin({
"process.env": {
"NODE_ENV": JSON.stringify("development")
},
DEVELOPMENT: JSON.stringify(true),
}),
new HtmlWebpackPlugin({
title: 'React Startkit UI',
template: './src/index.html',
favicon: './src/favicon.ico',
shim: {
fastclick: {
src: './src/libs/fastclick.js',
},
}
}),
new ExtractTextPlugin({
filename: 'css/[name].css',
allChunks: true,
}),
new OpenBrowserPlugin({
url: 'http://localhost:' + port,
}),
new webpack.HotModuleReplacementPlugin(),
new SpriteLoaderPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(), // 3.0新功能 范围提升(Scope Hoisting)
];
module.exports = {
entry: {
main: './src/index.jsx',
},
// 打包
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'js/[name].js',
publicPath: '/',
},
// 解析
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader'],
},
{
test: /\.(scss|sass)$/,
use: ['css-hot-loader'].concat(ExtractTextPlugin.extract({
fallback: "style-loader",
use: ['css-loader', 'postcss-loader', 'sass-loader'],
})),
},
{
test: /\.css$/,
use: ['css-hot-loader'].concat(ExtractTextPlugin.extract({
fallback: "style-loader",
use: ['css-loader', 'postcss-loader'],
})),
},
{
test: /\.(woff|woff2|eot|ttf)(\?.*$|$)/,
use: ['url-loader'],
},
{
test: /\.(gif|png|jpe?g)$/i,
use: [
'url-loader?limit=1000&name=assets/images/[name].[ext]',
'image-webpack-loader',
],
},
{
test: /\.svg$/,
loader: 'svg-sprite-loader',
include: [
path.resolve(__dirname, 'src/assets/svg'),
],
},
]
},
resolve: {
extensions: ['.js', '.jsx', '.json', '.scss', '.css'],
alias: {
'@': path.resolve(__dirname, 'src')
}
},
// 插件
plugins: plugins,
// 启动dev source map,出错以后就会采用source-map的形式直接显示你出错代码的位置。
devtool: 'eval-source-map',
// enable dev server
devServer: {
port: port,
host: '0.0.0.0',
disableHostCheck: true, // 解决配置 host: '0.0.0.0' 时, 出现 invalid host header
historyApiFallback: true,
hot: true,
inline: true,
// 代理请求
proxy: {
}
},
};