element/build/cooking.demo.js

87 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-07-27 14:15:02 +08:00
var cooking = require('cooking');
var config = require('./config');
2016-08-20 00:38:59 +08:00
var md = require('markdown-it')();
var striptags = require('./strip-tags');
2016-07-27 14:15:02 +08:00
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));
2016-08-23 16:57:58 +08:00
});
return str;
}
2016-07-27 14:15:02 +08:00
cooking.set({
2016-09-21 14:38:07 +08:00
entry: './examples/entry.js',
2016-07-27 14:15:02 +08:00
dist: './examples/element-ui/',
2016-09-20 18:51:35 +08:00
template: './examples/index.tpl',
2016-10-19 14:23:22 +08:00
publicPath: process.env.CI_ENV || '/',
2016-07-27 14:15:02 +08:00
hash: true,
devServer: {
port: 8085,
log: false,
publicPath: '/'
},
2016-09-06 11:51:08 +08:00
minimize: true,
2016-09-21 14:38:07 +08:00
chunk: true,
2016-07-27 14:15:02 +08:00
extractCSS: true,
2016-09-21 14:38:07 +08:00
sourceMap: true,
alias: config.alias,
2016-09-06 11:51:08 +08:00
extends: ['vue2', 'lint'],
2016-10-11 19:00:37 +08:00
postcss: config.postcss
2016-07-27 14:15:02 +08:00
});
cooking.add('loader.md', {
test: /\.md$/,
loader: 'vue-markdown-loader'
});
cooking.add('vueMarkdown', {
use: [
2016-08-22 14:04:03 +08:00
[require('markdown-it-container'), 'demo', {
2016-08-20 00:38:59 +08:00
validate: function(params) {
2016-08-23 16:57:58 +08:00
return params.trim().match(/^demo\s*(.*)$/);
2016-08-20 00:38:59 +08:00
},
render: function(tokens, idx) {
2016-08-23 16:57:58 +08:00
var m = tokens[idx].info.trim().match(/^demo\s*(.*)$/);
2016-08-20 00:38:59 +08:00
if (tokens[idx].nesting === 1) {
2016-08-23 13:46:51 +08:00
var description = (m && m.length > 1) ? m[1] : '';
2016-08-23 16:57:58 +08:00
var html = convert(striptags(tokens[idx + 1].content, 'script'));
2016-08-23 13:46:51 +08:00
var descriptionHTML = description
? '<div class="description">' + md.render(description) + '</div>'
: '';
2016-08-23 16:57:58 +08:00
return `<demo-block class="demo-box">
2016-08-22 14:04:03 +08:00
<div class="source">${html}</div>
<div class="meta">
2016-08-23 13:46:51 +08:00
${descriptionHTML}
2016-08-22 14:04:03 +08:00
<div class="highlight">`;
2016-08-20 00:38:59 +08:00
}
2016-08-23 16:57:58 +08:00
return '</div></div></demo-block>\n';
2016-08-20 00:38:59 +08:00
}
2016-07-27 14:15:02 +08:00
}]
],
preprocess: function(MarkdownIt, source) {
MarkdownIt.renderer.rules.table_open = function() {
2016-07-27 14:15:02 +08:00
return '<table class="table">';
};
MarkdownIt.renderer.rules.fence = wrap(MarkdownIt.renderer.rules.fence);
return source;
}
});
var wrap = function(render) {
return function() {
2016-07-27 14:15:02 +08:00
return render.apply(this, arguments)
.replace('<code class="', '<code class="hljs ')
.replace('<code>', '<code class="hljs">');
2016-07-27 14:15:02 +08:00
};
};
2016-09-21 14:38:07 +08:00
if (process.env.NODE_ENV === 'production') {
cooking.add('externals.vue', 'Vue');
cooking.add('externals.vue-router', 'VueRouter');
}
2016-10-22 00:45:18 +08:00
cooking.add('vue.preserveWhitespace', false);
2016-07-27 14:15:02 +08:00
module.exports = cooking.resolve();