-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvue.config.js
108 lines (105 loc) · 3.09 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
/**
* vue-cli3的全局配置文件 详情见https://cli.vuejs.org/zh/config/#%E5%85%A8%E5%B1%80-cli-%E9%85%8D%E7%BD%AE
*
*/
const isProduction = process.env.NODE_ENV === "production";
const path = require("path");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
function resolve(dir) {
return path.join(__dirname, dir);
}
function wrapCustomClass(render) {
return function (...args) {
return render(...args)
.replace('<code class="', '<code class="hljs ')
.replace("<code>", '<code class="hljs">');
};
}
module.exports = {
publicPath: isProduction ? "./" : "/",
devServer: {
overlay: {
//Show eslink error information on Browser
warnings: true,
errors: true
},
open: true,
port: 3000
},
productionSourceMap: false,
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,
preprocess: (MarkdownIt, source) => {
MarkdownIt.renderer.rules.table_open = function () {
return '<table class="table">';
};
MarkdownIt.renderer.rules.fence = wrapCustomClass(MarkdownIt.renderer.rules.fence);
const code_inline = MarkdownIt.renderer.rules.code_inline;
MarkdownIt.renderer.rules.code_inline = function (...args) {
args[0][args[1]].attrJoin("class", "code-show");
return code_inline(...args);
};
return source;
},
use: [
[
require("markdown-it-container"),
"code",
{
validate: params => params.trim().match(/^code\s*(.*)$/),
// 使用code-show 组件包裹内容并渲染
render: function (tokens, idx) {
if (tokens[idx].nesting === 1) {
return `<code-show>
<div slot="highlight">`;
}
return "</div></code-show>";
}
}
]
]
});
},
configureWebpack: config => {
config.resolve = {
extensions: [".js", ".vue", ".json", ".css"],
alias: {
vue$: "vue/dist/vue.esm.js",
"@": resolve("src"),
"&": resolve("libs")
}
};
//删除console插件
let plugins = [
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false, // 在UglifyJs删除没有用到的代码时不输出警告
drop_console: true, // 是否删除 console.log
drop_debugger: true, // 是否删除 debugger
collapse_vars: true // 内嵌定义了但是只用到一次的变量
},
output: {
// 去掉注释内容
comments: false
}
},
sourceMap: false,
parallel: true
})
];
//只有打包生产环境才需要将console删除
if (isProduction) {
config.plugins = [...config.plugins, ...plugins];
}
}
};