diff options
author | Constance Okoghenun <cokoghenun@gitlab.com> | 2018-02-27 22:18:28 +0300 |
---|---|---|
committer | Constance Okoghenun <cokoghenun@gitlab.com> | 2018-02-27 22:18:28 +0300 |
commit | 56b323914e7bfbe2a9e09994422977af404d1e51 (patch) | |
tree | fea01aaaef405dbd1a4d8e6d44cc8ef4c58f6d73 /config | |
parent | 8c122d65bfed5c5addd3245304895b98f8b83b36 (diff) | |
parent | d4867c518f2d72125c619c191fa9577dabb1ae9a (diff) |
Merge branch 'master' of https://gitlab.com/gitlab-org/gitlab-ce into protected-tags-bundle-refactor
Diffstat (limited to 'config')
-rw-r--r-- | config/webpack.config.js | 88 |
1 files changed, 50 insertions, 38 deletions
diff --git a/config/webpack.config.js b/config/webpack.config.js index 6fee0b5128b..5e841b59c9f 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -21,63 +21,49 @@ var DEV_SERVER_LIVERELOAD = process.env.DEV_SERVER_LIVERELOAD !== 'false'; var WEBPACK_REPORT = process.env.WEBPACK_REPORT; var NO_COMPRESSION = process.env.NO_COMPRESSION; -// generate automatic entry points -var autoEntries = {}; -var pageEntries = glob.sync('pages/**/index.js', { cwd: path.join(ROOT_PATH, 'app/assets/javascripts') }); - -// filter out entries currently imported dynamically in dispatcher.js -var dispatcher = fs.readFileSync(path.join(ROOT_PATH, 'app/assets/javascripts/dispatcher.js')).toString(); -var dispatcherChunks = dispatcher.match(/(?!import\(')\.\/pages\/[^']+/g); - -function generateAutoEntries(path, prefix = '.') { - const chunkPath = path.replace(/\/index\.js$/, ''); - if (!dispatcherChunks.includes(`${prefix}/${chunkPath}`)) { +var autoEntriesCount = 0; +var watchAutoEntries = []; + +function generateEntries() { + // generate automatic entry points + var autoEntries = {}; + var pageEntries = glob.sync('pages/**/index.js', { cwd: path.join(ROOT_PATH, 'app/assets/javascripts') }); + watchAutoEntries = [ + path.join(ROOT_PATH, 'app/assets/javascripts/pages/'), + ]; + + function generateAutoEntries(path, prefix = '.') { + const chunkPath = path.replace(/\/index\.js$/, ''); const chunkName = chunkPath.replace(/\//g, '.'); autoEntries[chunkName] = `${prefix}/${path}`; } -} -pageEntries.forEach(( path ) => generateAutoEntries(path)); + pageEntries.forEach(( path ) => generateAutoEntries(path)); -// report our auto-generated bundle count -var autoEntriesCount = Object.keys(autoEntries).length; -console.log(`${autoEntriesCount} entries from '/pages' automatically added to webpack output.`); + autoEntriesCount = Object.keys(autoEntries).length; -var config = { - // because sqljs requires fs. - node: { - fs: "empty" - }, - context: path.join(ROOT_PATH, 'app/assets/javascripts'), - entry: { + const manualEntries = { balsamiq_viewer: './blob/balsamiq_viewer.js', common: './commons/index.js', common_vue: './vue_shared/vue_resource_interceptor.js', cycle_analytics: './cycle_analytics/cycle_analytics_bundle.js', - commit_pipelines: './commit/pipelines/pipelines_bundle.js', - diff_notes: './diff_notes/diff_notes_bundle.js', environments: './environments/environments_bundle.js', - environments_folder: './environments/folder/environments_folder_bundle.js', filtered_search: './filtered_search/filtered_search_bundle.js', help: './help/help.js', merge_conflicts: './merge_conflicts/merge_conflicts_bundle.js', monitoring: './monitoring/monitoring_bundle.js', - network: './network/network_bundle.js', notebook_viewer: './blob/notebook_viewer.js', pdf_viewer: './blob/pdf_viewer.js', - pipelines: './pipelines/pipelines_bundle.js', pipelines_details: './pipelines/pipeline_details_bundle.js', profile: './profile/profile_bundle.js', project_import_gl: './projects/project_import_gitlab_project.js', protected_branches: './protected_branches', registry_list: './registry/index.js', - sidebar: './sidebar/sidebar_bundle.js', snippet: './snippet/snippet_bundle.js', sketch_viewer: './blob/sketch_viewer.js', stl_viewer: './blob/stl_viewer.js', terminal: './terminal/terminal_bundle.js', ui_development_kit: './ui_development_kit.js', - vue_merge_request_widget: './vue_merge_request_widget/index.js', two_factor_auth: './two_factor_auth.js', @@ -90,7 +76,15 @@ var config = { test: './test.js', u2f: ['vendor/u2f'], webpack_runtime: './webpack.js', - }, + }; + + return Object.assign(manualEntries, autoEntries); +} + +var config = { + context: path.join(ROOT_PATH, 'app/assets/javascripts'), + + entry: generateEntries, output: { path: path.join(ROOT_PATH, 'public/assets/webpack'), @@ -243,12 +237,9 @@ var config = { name: 'common_vue', chunks: [ 'boards', - 'commit_pipelines', 'cycle_analytics', 'deploy_keys', - 'diff_notes', 'environments', - 'environments_folder', 'filtered_search', 'groups', 'merge_conflicts', @@ -308,11 +299,15 @@ var config = { 'images': path.join(ROOT_PATH, 'app/assets/images'), 'vendor': path.join(ROOT_PATH, 'vendor/assets/javascripts'), 'vue$': 'vue/dist/vue.esm.js', + 'spec': path.join(ROOT_PATH, 'spec/javascripts'), } - } -} + }, -config.entry = Object.assign({}, autoEntries, config.entry); + // sqljs requires fs + node: { + fs: 'empty', + }, +}; if (IS_PRODUCTION) { config.devtool = 'source-map'; @@ -349,7 +344,24 @@ if (IS_DEV_SERVER) { }; config.plugins.push( // watch node_modules for changes if we encounter a missing module compile error - new WatchMissingNodeModulesPlugin(path.join(ROOT_PATH, 'node_modules')) + new WatchMissingNodeModulesPlugin(path.join(ROOT_PATH, 'node_modules')), + + // watch for changes to our automatic entry point modules + { + apply(compiler) { + compiler.plugin('emit', (compilation, callback) => { + compilation.contextDependencies = [ + ...compilation.contextDependencies, + ...watchAutoEntries, + ]; + + // report our auto-generated bundle count + console.log(`${autoEntriesCount} entries from '/pages' automatically added to webpack output.`); + + callback(); + }) + }, + }, ); if (DEV_SERVER_LIVERELOAD) { config.plugins.push(new webpack.HotModuleReplacementPlugin()); |