cooking.demo.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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('../src/utils/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: {
  14. app: './examples/entry.js',
  15. vendor: ['vue', 'vue-router']
  16. },
  17. dist: './examples/element-ui/',
  18. template: './examples/index.template.html',
  19. publicPath: '/element-ui/',
  20. hash: true,
  21. devServer: {
  22. port: 8085,
  23. log: false,
  24. publicPath: '/'
  25. },
  26. chunk: 'vendor',
  27. extractCSS: true,
  28. extends: {
  29. vue: true,
  30. lint: true,
  31. saladcss: {
  32. browser: ['ie > 8', 'last 2 version'],
  33. features: {
  34. 'bem': {
  35. 'shortcuts': {
  36. 'component': 'b',
  37. 'modifier': 'm',
  38. 'descendent': 'e'
  39. },
  40. 'separators': {
  41. 'descendent': '__',
  42. 'modifier': '--'
  43. }
  44. }
  45. }
  46. }
  47. }
  48. });
  49. cooking.add('loader.md', {
  50. test: /\.md$/,
  51. loader: 'vue-markdown-loader'
  52. });
  53. cooking.add('vueMarkdown', {
  54. use: [
  55. [require('markdown-it-toc-and-anchor').default, {
  56. anchorLinkSymbol: '',
  57. anchorClassName: 'anchor'
  58. }],
  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. cooking.add('resolve.alias', {
  97. 'main': path.join(__dirname, '../src'),
  98. 'packages': path.join(__dirname, '../packages'),
  99. 'examples': path.join(__dirname, '../examples')
  100. });
  101. var externals = {};
  102. Object.keys(Components).forEach(function (key) {
  103. externals[`packages/${key}/style.css`] = 'null';
  104. });
  105. // 开发模式不需要将不存在的 style.css 打包进去
  106. cooking.add('externals', externals);
  107. // cooking.config.vue.loaders.html = 'html?minimize=true&conservativeCollapse=false';
  108. module.exports = cooking.resolve();