cooking.demo.js 2.9 KB

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