From 9c8752d4521c7cffccf4313eca5cd6ff4f88c305 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Tue, 11 Oct 2016 12:30:30 +0800 Subject: [PATCH] Split common vendor javascript into chunks --- package.json | 2 ++ public/js/index.js | 5 ----- public/js/public.js | 4 ---- public/views/foot.ejs | 2 +- public/views/index.ejs | 3 +-- public/views/pretty.ejs | 2 +- public/views/slide.ejs | 2 +- webpack.config.js | 16 ++++++++++++++-- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 52f646e6..ea83c7af 100644 --- a/package.json +++ b/package.json @@ -120,6 +120,8 @@ "babel-loader": "^6.2.5", "bower-webpack-plugin": "^0.1.9", "css-loader": "^0.25.0", + "exports-loader": "^0.6.3", + "expose-loader": "^0.7.1", "extract-text-webpack-plugin": "^1.0.1", "file-loader": "^0.9.0", "imports-loader": "^0.6.5", diff --git a/public/js/index.js b/public/js/index.js index bac2c9d0..0c6bb03a 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -5,14 +5,9 @@ require('jquery-ui/ui/widgets/controlgroup'); require('jquery-ui/ui/widgets/autocomplete'); /* jquery and jquery plugins */ -require('jquery'); -require('jquery-textcomplete'); -require('jquery-mousewheel'); -require('jquery-scrollspy/jquery-scrollspy'); require('../vendor/showup/showup'); /* bootstrap */ -require('bootstrap'); require('bootstrap/dist/css/bootstrap.css'); require('prismjs/themes/prism.css'); diff --git a/public/js/public.js b/public/js/public.js index 858de389..b6d4f7a0 100644 --- a/public/js/public.js +++ b/public/js/public.js @@ -5,10 +5,6 @@ require('jquery-ui/ui/widgets/controlgroup'); require('jquery-ui/ui/widgets/autocomplete'); /* jquery and jquery plugins */ -require('jquery'); -require('jquery-textcomplete'); -require('jquery-mousewheel'); -require('jquery-scrollspy/jquery-scrollspy'); require('../vendor/showup/showup'); /* bootstrap */ diff --git a/public/views/foot.ejs b/public/views/foot.ejs index 150214f4..9ce320bc 100644 --- a/public/views/foot.ejs +++ b/public/views/foot.ejs @@ -23,7 +23,7 @@ <% } %> - + diff --git a/public/views/index.ejs b/public/views/index.ejs index 04a401a4..79ee5ddc 100644 --- a/public/views/index.ejs +++ b/public/views/index.ejs @@ -193,9 +193,8 @@ <% } else { %> - + - diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs index 6b1096bb..346cb272 100644 --- a/public/views/pretty.ejs +++ b/public/views/pretty.ejs @@ -90,7 +90,7 @@ <% } else { %> - + diff --git a/public/views/slide.ejs b/public/views/slide.ejs index 1549989f..8c248917 100644 --- a/public/views/slide.ejs +++ b/public/views/slide.ejs @@ -87,7 +87,7 @@ <% } else { %> - + diff --git a/webpack.config.js b/webpack.config.js index 5a7d6718..de2bb8b6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -17,14 +17,26 @@ module.exports = { new webpack.DefinePlugin({ "require.specified": "require.resolve" }), - new ExtractTextPlugin("[name].css") + new ExtractTextPlugin("[name].css"), + new webpack.optimize.CommonsChunkPlugin({ + name: "vendor", + filename: "vendor.bundle.js", + minChunks: Infinity, + }) ], entry: { index: path.join(__dirname, 'public/js/index.js'), public: path.join(__dirname, 'public/js/public.js'), slide: path.join(__dirname, 'public/js/slide.js'), - locale: path.join(__dirname, 'public/js/locale.js') + locale: path.join(__dirname, 'public/js/locale.js'), + vendor: [ + "expose?$!expose?jQuery!jquery", + "jquery-textcomplete", + "jquery-mousewheel", + "jquery-scrollspy/jquery-scrollspy", + "bootstrap" + ] }, output: {