2016-07-27 14:15:02 +08:00
|
|
|
var cooking = require('cooking');
|
2016-09-26 19:01:53 +08:00
|
|
|
var config = require('./config');
|
2016-08-20 00:38:59 +08:00
|
|
|
var md = require('markdown-it')();
|
2016-12-27 13:59:40 +08:00
|
|
|
var CopyWebpackPlugin = require('copy-webpack-plugin');
|
2016-09-26 19:01:53 +08:00
|
|
|
var striptags = require('./strip-tags');
|
2016-11-04 16:59:59 +08:00
|
|
|
var slugify = require('transliteration').slugify;
|
2016-11-05 19:56:34 +08:00
|
|
|
var isProd = process.env.NODE_ENV === 'production';
|
2016-11-14 14:10:58 +08:00
|
|
|
var isPlay = !!process.env.PLAY_ENV;
|
2016-07-27 14:15:02 +08:00
|
|
|
|
2016-09-09 11:51:28 +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-11-05 19:56:34 +08:00
|
|
|
entry: isProd ? {
|
|
|
|
docs: './examples/entry.js',
|
|
|
|
'element-ui': './src/index.js'
|
2016-11-14 14:10:58 +08:00
|
|
|
} : (isPlay ? './examples/play.js' : './examples/entry.js'),
|
2016-07-27 14:15:02 +08:00
|
|
|
dist: './examples/element-ui/',
|
2016-11-09 17:57:00 +08:00
|
|
|
template: [
|
|
|
|
{
|
|
|
|
template: './examples/index.tpl',
|
|
|
|
filename: './index.html',
|
|
|
|
favicon: './examples/favicon.ico'
|
|
|
|
}
|
|
|
|
],
|
2016-11-17 12:09:43 +08:00
|
|
|
publicPath: process.env.CI_ENV || '',
|
2016-07-27 14:15:02 +08:00
|
|
|
hash: true,
|
|
|
|
devServer: {
|
2016-12-09 14:44:00 +08:00
|
|
|
hostname: '0.0.0.0',
|
2016-07-27 14:15:02 +08:00
|
|
|
port: 8085,
|
|
|
|
log: false,
|
|
|
|
publicPath: '/'
|
|
|
|
},
|
2016-09-06 11:51:08 +08:00
|
|
|
minimize: true,
|
2016-11-05 19:56:34 +08:00
|
|
|
chunk: isProd ? {
|
|
|
|
'common': { name: ['element-ui', 'manifest'] }
|
|
|
|
} : false,
|
2016-07-27 14:15:02 +08:00
|
|
|
extractCSS: true,
|
2016-09-26 19:01:53 +08:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2016-11-18 19:43:07 +08:00
|
|
|
// fix publicPath
|
|
|
|
if (!process.env.CI_ENV) {
|
|
|
|
cooking.add('output.publicPath', '');
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
cooking.add('loader.md', {
|
|
|
|
test: /\.md$/,
|
|
|
|
loader: 'vue-markdown-loader'
|
|
|
|
});
|
|
|
|
|
2017-08-23 18:07:14 +08:00
|
|
|
cooking.add('loader.scss', {
|
|
|
|
test: /\.scss$/,
|
|
|
|
loaders: ['style-loader', 'css-loader', 'sass-loader']
|
|
|
|
});
|
|
|
|
|
2017-05-12 16:33:36 +08:00
|
|
|
cooking.add(
|
|
|
|
'output.chunkFilename',
|
|
|
|
isProd ? '[name].[chunkhash:7].js' : '[name].js'
|
|
|
|
);
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
cooking.add('vueMarkdown', {
|
|
|
|
use: [
|
2016-11-04 16:59:59 +08:00
|
|
|
[require('markdown-it-anchor'), {
|
|
|
|
level: 2,
|
|
|
|
slugify: slugify,
|
|
|
|
permalink: true,
|
|
|
|
permalinkBefore: true
|
|
|
|
}],
|
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
|
|
|
},
|
|
|
|
|
2016-09-09 11:51:28 +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-11-02 18:47:19 +08:00
|
|
|
var content = tokens[idx + 1].content;
|
2016-11-16 14:09:25 +08:00
|
|
|
var html = convert(striptags.strip(content, ['script', 'style'])).replace(/(<[^>]*)=""(?=.*>)/g, '$1');
|
2016-11-02 18:47:19 +08:00
|
|
|
var script = striptags.fetch(content, 'script');
|
2016-11-09 16:02:16 +08:00
|
|
|
var style = striptags.fetch(content, 'style');
|
|
|
|
var jsfiddle = { html: html, script: script, style: style };
|
2016-08-23 13:46:51 +08:00
|
|
|
var descriptionHTML = description
|
2016-11-08 15:59:02 +08:00
|
|
|
? md.render(description)
|
2016-08-23 13:46:51 +08:00
|
|
|
: '';
|
2016-11-02 18:47:19 +08:00
|
|
|
|
|
|
|
jsfiddle = md.utils.escapeHtml(JSON.stringify(jsfiddle));
|
|
|
|
|
|
|
|
return `<demo-block class="demo-box" :jsfiddle="${jsfiddle}">
|
2016-11-08 15:59:02 +08:00
|
|
|
<div class="source" slot="source">${html}</div>
|
|
|
|
${descriptionHTML}
|
|
|
|
<div class="highlight" slot="highlight">`;
|
2016-08-20 00:38:59 +08:00
|
|
|
}
|
2016-11-08 15:59:02 +08:00
|
|
|
return '</div></demo-block>\n';
|
2016-08-20 00:38:59 +08:00
|
|
|
}
|
2017-03-24 15:38:31 +08:00
|
|
|
}],
|
2017-07-24 19:09:36 +08:00
|
|
|
[require('markdown-it-container'), 'tip'],
|
|
|
|
[require('markdown-it-container'), 'warning']
|
2016-07-27 14:15:02 +08:00
|
|
|
],
|
2016-09-09 11:51:28 +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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-09 11:51:28 +08:00
|
|
|
var wrap = function(render) {
|
|
|
|
return function() {
|
2016-07-27 14:15:02 +08:00
|
|
|
return render.apply(this, arguments)
|
2017-10-16 14:07:24 +08:00
|
|
|
.replace('<code v-pre class="', '<code class="hljs ')
|
2016-09-09 11:51:28 +08:00
|
|
|
.replace('<code>', '<code class="hljs">');
|
2016-07-27 14:15:02 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-11-05 19:56:34 +08:00
|
|
|
if (isProd) {
|
2016-09-21 14:38:07 +08:00
|
|
|
cooking.add('externals.vue', 'Vue');
|
|
|
|
cooking.add('externals.vue-router', 'VueRouter');
|
|
|
|
}
|
|
|
|
|
2016-12-27 13:59:40 +08:00
|
|
|
cooking.add('plugin.CopyWebpackPlugin', new CopyWebpackPlugin([
|
|
|
|
{ from: 'examples/versions.json' }
|
|
|
|
]));
|
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();
|