-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathvue.config.js
57 lines (54 loc) · 1.81 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
const markdownRender = require("markdown-it")();
module.exports = {
publicPath: "/nature-ui/dist",
pages: {
index: {
entry: "examples/main.js"
}
},
chainWebpack: config => {
config.resolve.alias.set("@img", "src/assets/imgs");
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,
use: [
[
require("markdown-it-container"),
"demo",
{
validate: function(params) {
return params.trim().match(/^demo\s*(.*)$/);
},
render: function(tokens, idx) {
if (tokens[idx].nesting === 1) {
// 1.获取第一行的内容使用markdown渲染html作为组件的描述
let demoInfo = tokens[idx].info.trim().match(/^demo\s+(.*)$/);
let description =
demoInfo && demoInfo.length > 1 ? demoInfo[1] : "";
let descriptionHTML = description
? markdownRender.render(description)
: "";
// 2.获取代码块内的html和js代码
let content = tokens[idx + 1].content;
// 3.使用自定义开发组件【DemoBlock】来包裹内容并且渲染成案例和代码示例
return `<demo-block>
<div class="source" slot="source">${content}</div>
${descriptionHTML}
<div class="highlight" slot="highlight">`;
} else {
return "</div></demo-block>\n";
}
}
}
]
]
});
}
};