-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.pro.config.js
128 lines (115 loc) · 3.77 KB
/
webpack.pro.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
/**
* 开发模式下的webpack配置
*/
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const pxtorem = require('postcss-pxtorem');
const config = {
entry: {
// 文件入口配置
main: './keyboard/index.js',
},
output: {
// 文件输出配置
filename: 'cxy-keyboard.js',
// 命名生成的JS
path: path.resolve(__dirname, 'dist'),
// 目标输出目录
publicPath: '',
// 模板、样式、脚本、图片等资源对应的server上的路径
library: 'cxyKeyboard',
// 库名
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
// use: [
// 'style-loader',
// 'css-loader',
// ],
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
}),
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
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: false,
}),
new webpack.optimize.OccurrenceOrderPlugin(),
// webapck 会给编译好的代码片段一个id用来区分
// 而这个插件会让webpack在id分配上优化并保持一致性。
// 具体是的优化是:webpack就能够比对id的使用频率和分布来得出最短的id分配给使用频率高的模块
new ExtractTextPlugin('cxy-keyboard.css'),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
},
}),
]
}
module.exports = config;