From ad90643c94dc97b1b63a8678add79c44dbd15e5a Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Sat, 26 Nov 2016 23:22:47 +0800 Subject: [PATCH] Optimize pretty page resource packing and load orders --- public/views/pretty.ejs | 44 ++++++++++++++---------------------- webpackBaseConfig.js | 50 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 30 deletions(-) diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs index f810a5a97..2ba49e898 100644 --- a/public/views/pretty.ejs +++ b/public/views/pretty.ejs @@ -18,22 +18,16 @@ <% if(useCDN) { %> + + - - <% } else { %> - - - - <% } %> - - - - - - - + <%- include build/pretty-header %> + <% } else { %> + + <%- include build/pretty-pack-header %> + <% } %> <%- include polyfill %> @@ -82,28 +76,24 @@ MathJax.Hub.Config({ messageStyle: "none", skipStartupTypeset: true ,tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']], processEscapes: true }}); <% if(useCDN) { %> + + + + -<% } else { %> - - - - - - -<% } %> - - - - - + <%- include build/pretty-scripts %> - +<% } else { %> + + +<%- include build/pretty-pack-scripts %> +<% } %> <%- include ga %> diff --git a/webpackBaseConfig.js b/webpackBaseConfig.js index 1aaf6c75a..ba5db4b71 100644 --- a/webpackBaseConfig.js +++ b/webpackBaseConfig.js @@ -71,18 +71,30 @@ module.exports = { filename: path.join(__dirname, 'public/views/build/cover-pack-scripts.ejs'), inject: false }), + new HtmlWebpackPlugin({ template: 'public/views/includes/header.ejs', - chunks: ['vendor', 'pretty'], + chunks: ['font', 'pretty-styles', 'pretty'], filename: path.join(__dirname, 'public/views/build/pretty-header.ejs'), inject: false }), + new HtmlWebpackPlugin({ + template: 'public/views/includes/header.ejs', + chunks: ['font-pack', 'pretty-styles-pack', 'pretty-styles', 'pretty'], + filename: path.join(__dirname, 'public/views/build/pretty-pack-header.ejs'), + inject: false + }), new HtmlWebpackPlugin({ template: 'public/views/includes/scripts.ejs', - chunks: ['vendor', 'pretty'], + chunks: ['pretty'], filename: path.join(__dirname, 'public/views/build/pretty-scripts.ejs'), inject: false }), new HtmlWebpackPlugin({ + template: 'public/views/includes/scripts.ejs', + chunks: ['common', 'pretty-pack'], + filename: path.join(__dirname, 'public/views/build/pretty-pack-scripts.ejs'), + inject: false + }), template: 'public/views/includes/header.ejs', chunks: ['vendor', 'slide'], filename: path.join(__dirname, 'public/views/build/slide-header.ejs'), @@ -121,7 +133,6 @@ module.exports = { ], entry: { - pretty: path.join(__dirname, 'public/js/pretty.js'), slide: path.join(__dirname, 'public/js/slide.js'), font: path.join(__dirname, 'public/css/google-font.css'), "font-pack": path.join(__dirname, 'public/css/font.css'), @@ -222,6 +233,39 @@ module.exports = { path.join(__dirname, 'public/js/reveal-markdown.js'), path.join(__dirname, 'public/js/index.js') ], + pretty: [ + "expose?filterXSS!xss", + "flowchart.js", + "js-sequence-diagrams", + path.join(__dirname, 'public/js/reveal-markdown.js'), + path.join(__dirname, 'public/js/pretty.js') + ], + "pretty-styles": [ + path.join(__dirname, 'public/css/github-extract.css'), + path.join(__dirname, 'public/css/mermaid.css'), + path.join(__dirname, 'public/css/markdown.css') + ], + "pretty-styles-pack": [ + path.join(__dirname, 'node_modules/bootstrap/dist/css/bootstrap.min.css'), + path.join(__dirname, 'node_modules/font-awesome/css/font-awesome.min.css'), + path.join(__dirname, 'node_modules/ionicons/css/ionicons.min.css'), + path.join(__dirname, 'node_modules/octicons/octicons/octicons.css') + ], + "pretty-pack": [ + "expose?jsyaml!js-yaml", + "script!mermaid", + "expose?moment!moment", + "script!handlebars", + "expose?hljs!highlight.js", + "expose?emojify!emojify.js", + "expose?filterXSS!xss", + "script!gist-embed", + "flowchart.js", + "js-sequence-diagrams", + "expose?Viz!viz.js", + path.join(__dirname, 'public/js/reveal-markdown.js'), + path.join(__dirname, 'public/js/pretty.js') + ], ] },