From 0add3eaddc3bf7932904bf6498c4c7c7a0b897f3 Mon Sep 17 00:00:00 2001 From: Gunther Brunner Date: Wed, 2 Jul 2014 20:08:21 +0900 Subject: [PATCH] Separated webpack entries from chunks so the big chunks can be cached easily. --- lib/roles/app.js | 3 ++ res/app/app.js | 69 ++++++++++++++++++---------------- res/app/views/index.jade | 3 +- res/auth-ldap/scripts/entry.js | 5 +++ res/auth-mock/scripts/entry.js | 5 +++ webpack.config.js | 11 +++++- 6 files changed, 61 insertions(+), 35 deletions(-) create mode 100644 res/auth-ldap/scripts/entry.js create mode 100644 res/auth-mock/scripts/entry.js diff --git a/lib/roles/app.js b/lib/roles/app.js index 2889cf91..95660aac 100644 --- a/lib/roles/app.js +++ b/lib/roles/app.js @@ -40,6 +40,9 @@ module.exports = function(options) { app.use('/static/build', webpack({ debug: true , devtool: 'eval' + , stats: { + colors: true + } })) } diff --git a/res/app/app.js b/res/app/app.js index 6f65e16f..5afb9d65 100644 --- a/res/app/app.js +++ b/res/app/app.js @@ -1,35 +1,40 @@ -require('angular') -require('angular-route') -require('angular-touch') +require.ensure([], function (require) { -require('angular-gettext') -require('ng-file-upload') -require('angular-hotkeys') + require('angular') + require('angular-route') + require('angular-touch') -angular.module('app', [ - 'ngRoute', - 'ngTouch', - 'gettext', - 'angularFileUpload', - 'cfp.hotkeys', - require('./layout').name, - require('./device-list').name, - require('./control-panes').name, - require('./menu').name, - require('./settings').name, - require('./help').name, - require('./../common/lang').name, - require('./../test/samples/vs-repeat').name -]) - .config(['$routeProvider', '$locationProvider', - function ($routeProvider, $locationProvider) { - $locationProvider.hashPrefix('!'); - $routeProvider - .otherwise({ - redirectTo: '/devices' - }) - } + require('angular-gettext') + require('ng-file-upload') + require('angular-hotkeys') + + angular.module('app', [ + 'ngRoute', + 'ngTouch', + 'gettext', + 'angularFileUpload', + 'cfp.hotkeys', + require('./layout').name, + require('./device-list').name, + require('./control-panes').name, + require('./menu').name, + require('./settings').name, + require('./help').name, + require('./../common/lang').name, + require('./../test/samples/vs-repeat').name ]) - .config(function(hotkeysProvider) { - hotkeysProvider.includeCheatSheet = false - }) + .config(['$routeProvider', '$locationProvider', + function ($routeProvider, $locationProvider) { + $locationProvider.hashPrefix('!'); + $routeProvider + .otherwise({ + redirectTo: '/devices' + }) + } + ]) + .config(function (hotkeysProvider) { + hotkeysProvider.includeCheatSheet = false + }) + + +}) diff --git a/res/app/views/index.jade b/res/app/views/index.jade index b130cc61..e18f5090 100644 --- a/res/app/views/index.jade +++ b/res/app/views/index.jade @@ -23,5 +23,6 @@ html div(ng-view).fill-height script var APP = !{JSON.stringify(APP)} - script(src='/static/build/bundle.js') + script(src='/static/build/commons.entry.js') + script(src='/static/build/app.entry.js') script(src='/static/bower_components/stf-analytics/analytics.js') diff --git a/res/auth-ldap/scripts/entry.js b/res/auth-ldap/scripts/entry.js new file mode 100644 index 00000000..2e6bdc4b --- /dev/null +++ b/res/auth-ldap/scripts/entry.js @@ -0,0 +1,5 @@ +require.ensure([], function (require) { + require('angular') + require('angular-route') + +}) diff --git a/res/auth-mock/scripts/entry.js b/res/auth-mock/scripts/entry.js new file mode 100644 index 00000000..2e6bdc4b --- /dev/null +++ b/res/auth-mock/scripts/entry.js @@ -0,0 +1,5 @@ +require.ensure([], function (require) { + require('angular') + require('angular-route') + +}) diff --git a/webpack.config.js b/webpack.config.js index 115ee968..ae0956c2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,13 +1,19 @@ var pathutil = require('./lib/util/pathutil') var webpack = require('webpack') +var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin") module.exports = { cache: true -, entry: pathutil.resource('app/app.js') +, entry: { + app: pathutil.resource('app/app.js') + , authldap: pathutil.resource('auth-ldap/scripts/entry.js') + , authmock: pathutil.resource('auth-mock/scripts/entry.js') + } , output: { path: pathutil.resource('build') , publicPath: '/static/build/' - , filename: 'bundle.js' + , filename: 'entry/[name].entry.js' + , chunkFilename: '[id].[hash].chunk.js' } , stats: { colors: true @@ -78,5 +84,6 @@ module.exports = { , ['main'] ) ) + , new CommonsChunkPlugin("entry/commons.entry.js") ] }