From 900124810cd8d456644b9722d5d703abc751f217 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Mon, 15 Jan 2018 11:50:26 -0600 Subject: generate webpack entry points for pages directory automatically --- config/webpack.config.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'config/webpack.config.js') diff --git a/config/webpack.config.js b/config/webpack.config.js index 783677b5b8d..ed064be690c 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -3,6 +3,7 @@ var crypto = require('crypto'); var fs = require('fs'); var path = require('path'); +var glob = require('glob'); var webpack = require('webpack'); var StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin; var CopyWebpackPlugin = require('copy-webpack-plugin'); @@ -20,6 +21,15 @@ 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') }); + +pageEntries.forEach(( path ) => { + let chunkName = path.replace(/\/index\.js$/, '').replace(/\//g, '.'); + autoEntries[chunkName] = './' + path; +}); + var config = { // because sqljs requires fs. node: { @@ -301,6 +311,8 @@ var config = { } } +config.entry = Object.assign({}, autoEntries, config.entry); + if (IS_PRODUCTION) { config.devtool = 'source-map'; config.plugins.push( -- cgit v1.2.1 From 8ebe2f7ae6872ff8553fb0f3482df209270c874b Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Thu, 1 Feb 2018 17:23:03 -0600 Subject: prevent dynamic chunks from being duplicated by the dispatcher until it is completely refactored --- config/webpack.config.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'config/webpack.config.js') diff --git a/config/webpack.config.js b/config/webpack.config.js index ed064be690c..7f3fe551a03 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -25,11 +25,22 @@ var NO_COMPRESSION = process.env.NO_COMPRESSION; 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); + pageEntries.forEach(( path ) => { - let chunkName = path.replace(/\/index\.js$/, '').replace(/\//g, '.'); - autoEntries[chunkName] = './' + path; + let chunkPath = path.replace(/\/index\.js$/, ''); + if (!dispatcherChunks.includes(chunkPath)) { + let chunkName = chunkPath.replace(/\//g, '.'); + autoEntries[chunkName] = './' + path; + } }); +// report our auto-generated bundle count +var autoEntriesCount = Object.keys(autoEntries).length; +console.log(`${autoEntriesCount} entries from '/pages' automatically added to webpack output.`); + var config = { // because sqljs requires fs. node: { -- cgit v1.2.1