cooking.demo.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. var cooking = require('cooking');
  2. var path = require('path');
  3. var md = require('markdown-it')();
  4. var Components = require('../components.json');
  5. cooking.set({
  6. entry: {
  7. app: './examples/entry.js',
  8. vendor: ['vue', 'vue-router']
  9. },
  10. dist: './examples/element-ui/',
  11. template: './examples/index.template.html',
  12. publicPath: '/element-ui/',
  13. hash: true,
  14. devServer: {
  15. port: 8085,
  16. log: false,
  17. publicPath: '/'
  18. },
  19. chunk: 'vendor',
  20. extractCSS: true,
  21. extends: {
  22. vue: true,
  23. lint: true,
  24. saladcss: {
  25. browser: ['ie > 8', 'last 2 version'],
  26. features: {
  27. 'bem': {
  28. 'shortcuts': {
  29. 'component': 'b',
  30. 'modifier': 'm',
  31. 'descendent': 'e'
  32. },
  33. 'separators': {
  34. 'descendent': '__',
  35. 'modifier': '--'
  36. }
  37. }
  38. }
  39. }
  40. }
  41. });
  42. cooking.add('loader.md', {
  43. test: /\.md$/,
  44. loader: 'vue-markdown-loader'
  45. });
  46. cooking.add('vueMarkdown', {
  47. use: [
  48. [require('markdown-it-toc-and-anchor').default, {
  49. anchorLinkSymbol: '',
  50. anchorClassName: 'anchor'
  51. }],
  52. [require('markdown-it-container'), 'demo', {
  53. validate: function(params) {
  54. return params.trim().match(/^demo\s+(.*)$/);
  55. },
  56. render: function (tokens, idx) {
  57. var m = tokens[idx].info.trim().match(/^demo\s+(.*)$/);
  58. if (tokens[idx].nesting === 1) {
  59. var html = tokens[idx + 1].content;
  60. return `<section class="demo">
  61. <div class="source">${html}</div>
  62. <div class="meta">
  63. <div class="description">${md.utils.escapeHtml(m[1])}</div>
  64. <div class="highlight">`;
  65. }
  66. return '</section>\n';
  67. }
  68. }]
  69. ],
  70. preprocess: function (MarkdownIt, source) {
  71. MarkdownIt.renderer.rules.table_open = function () {
  72. return '<table class="table">';
  73. };
  74. MarkdownIt.renderer.rules.fence = wrap(MarkdownIt.renderer.rules.fence);
  75. return source;
  76. }
  77. });
  78. var wrap = function (render) {
  79. return function () {
  80. return render.apply(this, arguments)
  81. .replace('<code class="', '<code class="hljs ')
  82. .replace('<code>', '<code class="hljs">')
  83. };
  84. };
  85. cooking.add('resolve.alias', {
  86. 'main': path.join(__dirname, '../src'),
  87. 'packages': path.join(__dirname, '../packages'),
  88. 'examples': path.join(__dirname, '../examples')
  89. });
  90. var externals = {};
  91. Object.keys(Components).forEach(function (key) {
  92. externals[`packages/${key}/style.css`] = 'null';
  93. });
  94. // 开发模式不需要将不存在的 style.css 打包进去
  95. cooking.add('externals', externals);
  96. // cooking.config.vue.loaders.html = 'html?minimize=true&conservativeCollapse=false';
  97. module.exports = cooking.resolve();