diff options
author | Mike Greiling <mike@pixelcog.com> | 2017-03-02 01:01:33 +0300 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2017-03-04 01:47:38 +0300 |
commit | cb6c036d8942ab24048b9ecebcc6c3fa408c9a3e (patch) | |
tree | 148d8eaf97ed02498cb348baa8f844d4bbc5ee65 | |
parent | e80fa69895dadfbd5cdc95f7feb9593cfe52e9b6 (diff) |
create a common.js bundle and include all jQuery plugins
-rw-r--r-- | app/assets/javascripts/application.js | 18 | ||||
-rw-r--r-- | app/assets/javascripts/commons/bootstrap.js | 10 | ||||
-rw-r--r-- | app/assets/javascripts/commons/index.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/commons/jquery.js | 12 | ||||
-rw-r--r-- | app/views/layouts/_head.html.haml | 1 | ||||
-rw-r--r-- | config/webpack.config.js | 8 | ||||
-rw-r--r-- | spec/javascripts/test_bundle.js | 13 |
7 files changed, 34 insertions, 30 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4c24d35b5bb..8441a335ac0 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -6,23 +6,8 @@ /* global AwardsHandler */ /* global Aside */ -window.$ = window.jQuery = require('jquery'); -require('jquery-ujs'); -require('vendor/jquery.endless-scroll'); -require('vendor/jquery.waitforimages'); -require('vendor/jquery.caret'); -require('vendor/jquery.atwho'); -require('vendor/jquery.scrollTo'); +// common libraries window.Cookies = require('js-cookie'); -require('./autosave'); -require('bootstrap/js/affix'); -require('bootstrap/js/alert'); -require('bootstrap/js/dropdown'); -require('bootstrap/js/modal'); -require('bootstrap/js/tab'); -require('bootstrap/js/transition'); -require('bootstrap/js/tooltip'); -require('select2/select2.js'); window.Pikaday = require('pikaday'); window._ = require('underscore'); window.Dropzone = require('dropzone'); @@ -34,7 +19,6 @@ require('./shortcuts_navigation'); require('./shortcuts_dashboard_navigation'); require('./shortcuts_issuable'); require('./shortcuts_network'); -require('vendor/jquery.nicescroll'); // behaviors require('./behaviors/autosize'); diff --git a/app/assets/javascripts/commons/bootstrap.js b/app/assets/javascripts/commons/bootstrap.js new file mode 100644 index 00000000000..72e43d34a74 --- /dev/null +++ b/app/assets/javascripts/commons/bootstrap.js @@ -0,0 +1,10 @@ +require('./jquery'); + +// twitter bootstrap plugins +require('bootstrap-sass/assets/javascripts/bootstrap/affix'); +require('bootstrap-sass/assets/javascripts/bootstrap/alert'); +require('bootstrap-sass/assets/javascripts/bootstrap/dropdown'); +require('bootstrap-sass/assets/javascripts/bootstrap/modal'); +require('bootstrap-sass/assets/javascripts/bootstrap/tab'); +require('bootstrap-sass/assets/javascripts/bootstrap/transition'); +require('bootstrap-sass/assets/javascripts/bootstrap/tooltip'); diff --git a/app/assets/javascripts/commons/index.js b/app/assets/javascripts/commons/index.js new file mode 100644 index 00000000000..a9226bc1325 --- /dev/null +++ b/app/assets/javascripts/commons/index.js @@ -0,0 +1,2 @@ +require('./jquery'); +require('./bootstrap'); diff --git a/app/assets/javascripts/commons/jquery.js b/app/assets/javascripts/commons/jquery.js new file mode 100644 index 00000000000..9ef415d6a95 --- /dev/null +++ b/app/assets/javascripts/commons/jquery.js @@ -0,0 +1,12 @@ +// jQuery library +window.$ = window.jQuery = require('jquery'); + +// jQuery plugins +require('jquery-ujs'); +require('vendor/jquery.endless-scroll'); +require('vendor/jquery.caret'); +require('vendor/jquery.atwho'); +require('vendor/jquery.scrollTo'); +require('vendor/jquery.nicescroll'); +require('vendor/jquery.waitforimages'); +require('select2/select2.js'); diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index 302c1794628..29844b1027b 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -28,6 +28,7 @@ = stylesheet_link_tag "application", media: "all" = stylesheet_link_tag "print", media: "print" + = javascript_include_tag(*webpack_asset_paths("common")) = javascript_include_tag(*webpack_asset_paths("application")) - if content_for?(:page_specific_javascripts) diff --git a/config/webpack.config.js b/config/webpack.config.js index cbf59276dce..c2e0e86fb78 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -17,6 +17,7 @@ var WEBPACK_REPORT = process.env.WEBPACK_REPORT; var config = { context: path.join(ROOT_PATH, 'app/assets/javascripts'), entry: { + common: './commons/index.js', application: './application.js', blob_edit: './blob_edit/blob_edit_bundle.js', boards: './boards/boards_bundle.js', @@ -90,13 +91,18 @@ var config = { IS_PRODUCTION ? new webpack.HashedModuleIdsPlugin() : new webpack.NamedModulesPlugin(), + + // create a common.js bundle to be loaded on every page + new webpack.optimize.CommonsChunkPlugin({ + name: 'common', + minChunks: Infinity, + }), ], resolve: { extensions: ['.js', '.es6', '.js.es6'], alias: { '~': path.join(ROOT_PATH, 'app/assets/javascripts'), - 'bootstrap/js': 'bootstrap-sass/assets/javascripts/bootstrap', 'emoji-aliases$': path.join(ROOT_PATH, 'fixtures/emojis/aliases.json'), 'icons': path.join(ROOT_PATH, 'app/views/shared/icons'), 'vendor': path.join(ROOT_PATH, 'vendor/assets/javascripts'), diff --git a/spec/javascripts/test_bundle.js b/spec/javascripts/test_bundle.js index ca707d872a4..fae462561e9 100644 --- a/spec/javascripts/test_bundle.js +++ b/spec/javascripts/test_bundle.js @@ -5,23 +5,12 @@ jasmine.getFixtures().fixturesPath = 'base/spec/javascripts/fixtures'; jasmine.getJSONFixtures().fixturesPath = 'base/spec/javascripts/fixtures'; // include common libraries +require('~/commons/index.js'); window.$ = window.jQuery = require('jquery'); window._ = require('underscore'); window.Cookies = require('js-cookie'); window.Vue = require('vue'); window.Vue.use(require('vue-resource')); -require('jquery-ujs'); -require('bootstrap/js/affix'); -require('bootstrap/js/alert'); -require('bootstrap/js/button'); -require('bootstrap/js/collapse'); -require('bootstrap/js/dropdown'); -require('bootstrap/js/modal'); -require('bootstrap/js/scrollspy'); -require('bootstrap/js/tab'); -require('bootstrap/js/transition'); -require('bootstrap/js/tooltip'); -require('bootstrap/js/popover'); // stub expected globals window.gl = window.gl || {}; |