element/build/cooking.demo.js

87 lines
2.4 KiB
JavaScript
Raw Normal View History

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