forked from ElemeFE/element
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcooking.demo.js
94 lines (84 loc) · 2.6 KB
/
cooking.demo.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
var cooking = require('cooking');
var config = require('./config');
var md = require('markdown-it')();
var Components = require('../components.json');
var striptags = require('./strip-tags');
function convert(str) {
str = str.replace(/(&#x)(\w{4});/gi, function($0) {
return String.fromCharCode(parseInt(encodeURIComponent($0).replace(/(%26%23x)(\w{4})(%3B)/g, '$2'), 16));
});
return str;
}
cooking.set({
entry: './examples/entry.js',
dist: './examples/element-ui/',
template: './examples/index.tpl',
publicPath: process.env.CI_ENV || '/',
hash: true,
devServer: {
port: 8085,
log: false,
publicPath: '/'
},
minimize: true,
chunk: true,
extractCSS: true,
sourceMap: true,
alias: config.alias,
extends: ['vue2', 'lint'],
postcss: config.postcss
});
cooking.add('loader.md', {
test: /\.md$/,
loader: 'vue-markdown-loader'
});
cooking.add('vueMarkdown', {
use: [
[require('markdown-it-container'), 'demo', {
validate: function(params) {
return params.trim().match(/^demo\s*(.*)$/);
},
render: function(tokens, idx) {
var m = tokens[idx].info.trim().match(/^demo\s*(.*)$/);
if (tokens[idx].nesting === 1) {
var description = (m && m.length > 1) ? m[1] : '';
var html = convert(striptags(tokens[idx + 1].content, 'script'));
var descriptionHTML = description
? '<div class="description">' + md.render(description) + '</div>'
: '';
return `<demo-block class="demo-box">
<div class="source">${html}</div>
<div class="meta">
${descriptionHTML}
<div class="highlight">`;
}
return '</div></div></demo-block>\n';
}
}]
],
preprocess: function(MarkdownIt, source) {
MarkdownIt.renderer.rules.table_open = function() {
return '<table class="table">';
};
MarkdownIt.renderer.rules.fence = wrap(MarkdownIt.renderer.rules.fence);
return source;
}
});
var wrap = function(render) {
return function() {
return render.apply(this, arguments)
.replace('<code class="', '<code class="hljs ')
.replace('<code>', '<code class="hljs">');
};
};
var externals = {};
Object.keys(Components).forEach(function(key) {
externals[`element-ui/packages/${key}/style.css`] = 'null';
});
// 开发模式不需要将不存在的 style.css 打包进去
cooking.add('externals', externals);
if (process.env.NODE_ENV === 'production') {
cooking.add('externals.vue', 'Vue');
cooking.add('externals.vue-router', 'VueRouter');
}
module.exports = cooking.resolve();