-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.dev.config.js
164 lines (142 loc) · 4.56 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
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
/**
* 开发模式下的webpack配置
*/
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const pxtorem = require('postcss-pxtorem');
const config = {
entry: [
// 文件入口配置
'./index.js',
// './keyboard/index.js'
],
output: {
// 文件输出配置
filename: 'bundle.js',
// 命名生成的JS
path: path.resolve(__dirname, 'dist'),
// 目标输出目录
publicPath: '',
// 模板、样式、脚本、图片等资源对应的server上的路径
library: 'cxyKeyboard',
// 库名
},
devtool: 'inline-source-map',
devServer: {
// contentBase: path.resolve(__dirname, 'dist'),
port: '8888',
hot: true,
host: '0.0.0.0',
allowedHosts: [
'weichao.cx580.com',
]
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: {
loader: 'babel-loader',
options: {
presets: ['env'],
plugins: ['transform-runtime']
}
},
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
sourceMap: true,
importLoaders: 1,
localIdentName: 'ys-keyboard-[local]'
}
},
{
loader: 'postcss-loader',
options: {
parser: 'postcss-scss',
sourceMap: true,
plugins: (loader) => [
require('precss')(),
require('autoprefixer')(),
require('rucksack-css')(),
pxtorem({
rootValue: 100,
propWhiteList: [],
})
]
}
},
]
},
{
test: /\.(otf|eot|svg|ttf|woff|woff2).*$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000
}
}
]
},
{
test: /\.(gif|jpe?g|png|ico)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000
}
}
]
},
]
},
plugins: [
new webpack.LoaderOptionsPlugin({
debug: true,
}),
new HtmlWebpackPlugin({
template: './index.html',
// html模板的路径
title: 'Development',
// html的标题
filename: 'index.html',
// 文件名以及文件将要存放的位置
// favicon: './src/favicon.ico',
// favicon路径
inject: 'head',
// js插入的位置,true/'head' false/'body'
// chunks: ['main'],
// 指定引入的chunk,根据entry的key配置,不配置就会引入所有页面的资源
hash: false,
// 这样每次客户端页面就会根据这个hash来判断页面是否有必要刷新
// 在项目后续过程中,经常需要做些改动更新什么的,一但有改动,客户端页面就会自动更新!
// minify: {
// // 压缩HTML文件
// removeComments: true,
// // 移除HTML中的注释
// collapseWhitespace: true,
// // 删除空白符与换行符
// }
}),
new webpack.HotModuleReplacementPlugin(),
]
}
module.exports = config;