cooking.demo.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. var cooking = require('cooking');
  2. var config = require('./config');
  3. var md = require('markdown-it')();
  4. var Components = require('../components.json');
  5. var striptags = require('./strip-tags');
  6. function convert(str) {
  7. str = str.replace(/(&#x)(\w{4});/gi, function($0) {
  8. return String.fromCharCode(parseInt(encodeURIComponent($0).replace(/(%26%23x)(\w{4})(%3B)/g, '$2'), 16));
  9. });
  10. return str;
  11. }
  12. cooking.set({
  13. entry: './examples/entry.js',
  14. dist: './examples/element-ui/',
  15. template: './examples/index.tpl',
  16. publicPath: '/',
  17. hash: true,
  18. devServer: {
  19. port: 8085,
  20. log: false,
  21. publicPath: '/'
  22. },
  23. minimize: true,
  24. chunk: true,
  25. extractCSS: true,
  26. sourceMap: true,
  27. alias: config.alias,
  28. extends: ['vue2', 'lint'],
  29. postcss: function(webapck) {
  30. return [
  31. require('postcss-salad')({
  32. browser: ['ie > 8', 'last 2 version'],
  33. features: {
  34. 'partialImport': {
  35. addDependencyTo: webapck
  36. },
  37. 'bem': {
  38. 'shortcuts': {
  39. 'component': 'b',
  40. 'modifier': 'm',
  41. 'descendent': 'e'
  42. },
  43. 'separators': {
  44. 'descendent': '__',
  45. 'modifier': '--'
  46. }
  47. }
  48. }
  49. })
  50. ];
  51. }
  52. });
  53. cooking.add('loader.md', {
  54. test: /\.md$/,
  55. loader: 'vue-markdown-loader'
  56. });
  57. cooking.add('vueMarkdown', {
  58. use: [
  59. [require('markdown-it-container'), 'demo', {
  60. validate: function(params) {
  61. return params.trim().match(/^demo\s*(.*)$/);
  62. },
  63. render: function(tokens, idx) {
  64. var m = tokens[idx].info.trim().match(/^demo\s*(.*)$/);
  65. if (tokens[idx].nesting === 1) {
  66. var description = (m && m.length > 1) ? m[1] : '';
  67. var html = convert(striptags(tokens[idx + 1].content, 'script'));
  68. var descriptionHTML = description
  69. ? '<div class="description">' + md.render(description) + '</div>'
  70. : '';
  71. return `<demo-block class="demo-box">
  72. <div class="source">${html}</div>
  73. <div class="meta">
  74. ${descriptionHTML}
  75. <div class="highlight">`;
  76. }
  77. return '</div></div></demo-block>\n';
  78. }
  79. }]
  80. ],
  81. preprocess: function(MarkdownIt, source) {
  82. MarkdownIt.renderer.rules.table_open = function() {
  83. return '<table class="table">';
  84. };
  85. MarkdownIt.renderer.rules.fence = wrap(MarkdownIt.renderer.rules.fence);
  86. return source;
  87. }
  88. });
  89. var wrap = function(render) {
  90. return function() {
  91. return render.apply(this, arguments)
  92. .replace('<code class="', '<code class="hljs ')
  93. .replace('<code>', '<code class="hljs">');
  94. };
  95. };
  96. var externals = {};
  97. Object.keys(Components).forEach(function(key) {
  98. externals[`packages/${key}/style.css`] = 'null';
  99. });
  100. // 开发模式不需要将不存在的 style.css 打包进去
  101. cooking.add('externals', externals);
  102. if (process.env.NODE_ENV === 'production') {
  103. cooking.add('externals.vue', 'Vue');
  104. cooking.add('externals.vue-router', 'VueRouter');
  105. }
  106. module.exports = cooking.resolve();