-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathvue.config.js
124 lines (121 loc) · 4.21 KB
/
vue.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
const path = require('path')
const fs = require('fs')
// var Components = require('./components.json');
function resolve (dir) {
return path.join(__dirname, './', dir)
}
module.exports = {
productionSourceMap: process.env.Component === 'component' ? false : true,
outputDir: process.env.Component === 'component' ? 'lib' : 'dist',
pages: {
app: {
// page 的入口
entry: 'src/main.js',
// 模板来源
template: 'public/index.html',
// 在 dist/index.html 的输出
filename: 'index.html',
// 当使用 title 选项时,
// template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
title: 'Examples',
// 在这个页面中包含的块,默认情况下会包含
// 提取出来的通用 chunk 和 vendor chunk。
chunks: ['chunk-vendors', 'chunk-common', 'app']
},
demos: {
// page 的入口
entry: 'src/demos.js',
// 模板来源
template: 'public/index.html',
// 在 dist/index.html 的输出
filename: 'demos.html',
// 当使用 title 选项时,
// template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
title: 'Demo',
// 在这个页面中包含的块,默认情况下会包含
// 提取出来的通用 chunk 和 vendor chunk。
chunks: ['chunk-vendors', 'chunk-common', 'demos']
}
},
configureWebpack: config => {
if (process.env.Component === 'component') {
config.plugins = config.plugins.filter(item => {
return ['HtmlWebpackPlugin', 'CopyPlugin', 'ESLintWebpackPlugin'].indexOf(item.constructor.name) === -1
})
config.performance = {
hints: false
}
config.stats = {
children: false
}
config.optimization = {
minimize: true
}
var Components = {
"index": "./packages"
}
var ComponentsPath = './packages'
const files = fs.readdirSync(ComponentsPath)
files.forEach(function (item) {
let p = ComponentsPath + "/" + item
let stat = fs.lstatSync(p)
if (stat.isDirectory() === true && ['style'].indexOf(item) == -1) {
Components[item] = p
}
})
config.entry = Components
config.externals = {
vue: 'vue',
qrcodejs2: 'qrcodejs2',
swiper: 'swiper',
photoswipe: 'photoswipe',
'photoswipe/dist/photoswipe-ui-default': 'photoswipe/dist/photoswipe-ui-default',
'photoswipe/dist/photoswipe.css': 'photoswipe/dist/photoswipe.css',
'photoswipe/dist/default-skin/default-skin.css': 'photoswipe/dist/default-skin/default-skin.css',
'swiper/dist/css/swiper.min.css': 'swiper/dist/css/swiper.min.css',
...config.externals
}
config.output.filename = '[name].js'
config.output.chunkFilename = '[id].js'
config.output.libraryTarget = 'commonjs2'
}
// console.log('plugins', config.module.rules)
},
chainWebpack: config => {
config.module
.rule("md")
.test(/\.md/)
.use("vue-loader")
.loader("vue-loader")
.end()
.use("vue-markdown-loader")
.loader("vue-markdown-loader/lib/markdown-compiler")
.options({
raw: true,
preventExtract: true,
preprocess: function(markdownIt, source) {
var result = source.match(/##:(\w+):##/g)
if (result && result[0]) {
var component = result[0].replace(/##:/g, '').replace(/:##/g, '')
if (component) {
var text = fs.readFileSync(resolve('src/demos/'+component+'.vue'), 'utf8')
return source.replace(result[0], text).replace(RegExp(`.scss`, 'g'), '.css')
}
}
// do any thing
return source
}
})
const oneOfsMap = config.module.rule('scss').oneOfs.store
oneOfsMap.forEach(item => {
item
.use('sass-resources-loader')
.loader('sass-resources-loader')
.options({
// Or array of paths
resources: ['./packages/style/src/theme/common/variable.scss', './packages/style/src/theme/common/mixins.scss']
})
.end()
})
}
}