-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
131 lines (120 loc) · 3.11 KB
/
index.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
const Path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const DEFAULT_OPTIONS = {
// css output path
cssOutputDir: 'style',
// add hash fingerprint to extract css files
cssUseHash: true,
// if extract css files or not
extractCss: false,
// extracted css' file name
extractFilename: 'components',
// enable postcss
enablePostCss: false,
// enable lint to js&vue files
enableLint: false
};
module.exports = function (opts) {
const Options = Object.assign({}, DEFAULT_OPTIONS, opts);
const Plugins = [];
const PublicPath = Options.extractCss && Options.cssOutputDir ? '../' : '';
const Filename = `[name]${Options.extractFilename?'-'+Options.extractFilename:''}`;
// extract css files
const ExtractPlugin = new ExtractTextPlugin({
filename: `${Path.basename(Options.cssOutputDir)}/${Filename}${Options.cssUseHash?'.[contenthash:8].css':'.css'}`,
allChunks: true,
ignoreOrder: true
});
if(Options.extractCss){
Plugins.push(ExtractPlugin);
}
function GetLoaders() {
const BaseLoaders = [];
BaseLoaders.push({
loader: 'css-loader',
options: {
url: true,
minimize: process.env.BOI_ENV === 'dev' ? false : true
}
});
if (Options.enablePostCss) {
BaseLoaders.push({
loader: 'postcss-loader'
});
}
return {
css: Options.extractCss ? ExtractTextPlugin.extract({
use: BaseLoaders,
fallback: 'vue-style-loader',
publicPath: PublicPath
}) : [{
loader: 'vue-style-loader'
}].concat(BaseLoaders),
less: Options.extractCss ? ExtractTextPlugin.extract({
use: BaseLoaders.concat(['less-loader']),
fallback: 'vue-style-loader',
publicPath: PublicPath
}) : [{
loader: 'vue-style-loader'
}].concat(BaseLoaders, ['less-loader']),
scss: Options.extractCss ? ExtractTextPlugin.extract({
use: BaseLoaders.concat(['sass-loader']),
fallback: 'vue-style-loader',
publicPath: PublicPath
}) : [{
loader: 'vue-style-loader'
}].concat(BaseLoaders, ['sass-loader'])
};
}
const Rules = [{
test: /\.vue$/,
use: [{
loader: 'vue-loader',
options: {
loaders: GetLoaders()
}
}]
}];
if(Options.enableLint){
Rules.unshift({
test: /\.vue$/,
enforce: 'pre',
exclude: '/node_modules/',
use: [{
loader: 'eslint-loader',
options: {
emitError: true,
emitWarning: true,
failOnError: true,
formatter: require('eslint-friendly-formatter')
}
}]
});
}
return {
webpackConf: {
module: {
rules: Rules
},
plugins: Plugins,
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
}
},
dependencies: [
'eslint',
'vue-loader',
'less-loader',
'sass-loader',
'eslint-loader',
'postcss-loader',
'vue-style-loader'
],
alias: {
'vue': 'vue/dist/vue.esm.js'
}
};
};