-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-dev-config.js
115 lines (107 loc) · 3.82 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
/**
* 开发模式下的webpack配置
* 在整个项目开发过程中,几乎99%的时间都是在这个模式下进行的
* 注意。两种模式的配置有较大差异!!
*/
const path = require('path');
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin'
import precss from 'precss'
import autoprefixer from 'autoprefixer'
import rucksackCss from 'rucksack-css'
// import px2rem from 'postcss-pxtorem';
// const px2remOpts = {
// rootValue: 100,
// propWhiteList: [],
// };
export default {
debug: true,
devtool: 'cheap-module-eval-source-map', // more info:https://webpack.github.io/docs/build-performance.html#sourcemaps and https://webpack.github.io/docs/configuration.html#devtool
noInfo: true, // set to false to see a list of every file being bundled.
entry: [
'./src/webpack-public-path', // 服务器静态资源路径配置,保证首先载入
'react-hot-loader/patch',
'webpack-hot-middleware/client?reload=true',
path.resolve(__dirname, 'src/js/index.js')
],
target: 'web', // necessary per https://webpack.github.io/docs/testing.html#compile-and-test
output: {
path: `${__dirname}/src`, // Note: Physical files are only output by the production build task `npm run build`.
publicPath: '/',
filename: 'bundle.js'
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'), // Tells React to build in either dev or prod modes. https://facebook.github.io/react/downloads.html (See bottom)
__DEV__: true
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin({ // Create HTML file that includes references to bundled CSS and JS.
template: 'src/index.html',
title: '表单设计器',
favicon:'./src/favicon.ico',
minify: {
removeComments: true,
collapseWhitespace: true
},
hash:true,
// 这样每次客户端页面就会根据这个hash来判断页面是否有必要刷新
// 在项目后续过程中,经常需要做些改动更新什么的,一但有改动,客户端页面就会自动更新!
inject: 'body'
})
],
resolve: {
modulesDirectories: ['node_modules', path.join(__dirname, '../node_modules')],
extensions: ['', '.web.js', '.js', '.json'],
// 路径别名, 懒癌福音
alias:{
app:path.resolve(__dirname,'src/js'),
// 以前你可能这样引用 import { Nav } from '../../components'
// 现在你可以这样引用 import { Nav } from 'app/components'
style:path.resolve(__dirname,'src/styles')
// 以前你可能这样引用 import "../../../styles/mixins.scss"
// 现在你可以这样引用 import "style/mixins.scss"
// 注意:别名只能在.js文件中使用。
}
},
module: {
loaders: [
{
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/
},
{
test: /\.scss$/,
include: path.resolve(__dirname, 'src/js'),
loaders: [
'style',
'css?modules&sourceMap&importLoaders=1&localIdentName=[local]___[hash:base64:5]',
'postcss?parser=postcss-scss'
]
},
// 组件样式,需要私有化,单独配置
{
test: /\.scss$/,
include: path.resolve(__dirname, 'src/styles'),
loader: 'style!css!postcss?parser=postcss-scss'
},
// 公有样式,不需要私有化,单独配置
{
test: /\.css$/,
include: path.resolve(__dirname, 'node_modules'),
loader: 'style!css!postcss'
},
{
test: /\.(otf|eot|svg|ttf|woff|woff2).*$/,
loader: 'url?limit=10000'
},
{
test: /\.(gif|jpe?g|png|ico)$/,
loader: 'url?limit=10000'
}
]
},
postcss: ()=> [precss,autoprefixer,rucksackCss]
};