Commit 94a9c60e authored by Mike Greiling's avatar Mike Greiling

combine ancestor entrypoints into child entrypoints instead of importing bundles for each

parent d224b59a
...@@ -6,7 +6,7 @@ module WebpackHelper ...@@ -6,7 +6,7 @@ module WebpackHelper
end end
def webpack_controller_bundle_tags def webpack_controller_bundle_tags
bundles = [] chunks = []
action = case controller.action_name action = case controller.action_name
when 'create' then 'new' when 'create' then 'new'
...@@ -15,19 +15,16 @@ module WebpackHelper ...@@ -15,19 +15,16 @@ module WebpackHelper
end end
route = [*controller.controller_path.split('/'), action].compact route = [*controller.controller_path.split('/'), action].compact
entrypoint = "pages.#{route.join('.')}"
until route.empty?
begin begin
asset_paths = entrypoint_paths("pages.#{route.join('.')}", extension: 'js') chunks = entrypoint_paths(entrypoint, extension: 'js')
bundles.unshift(*asset_paths)
rescue Gitlab::Webpack::Manifest::AssetMissingError rescue Gitlab::Webpack::Manifest::AssetMissingError
# no bundle exists for this path # no bundle exists for this path
chunks = entrypoint_paths("default", extension: 'js')
end end
route.pop javascript_include_tag(*chunks)
end
javascript_include_tag(*bundles.uniq)
end end
def entrypoint_paths(source, extension: nil, force_same_domain: false) def entrypoint_paths(source, extension: nil, force_same_domain: false)
......
...@@ -25,6 +25,7 @@ const defaultEntries = ['./webpack', './commons', './main']; ...@@ -25,6 +25,7 @@ const defaultEntries = ['./webpack', './commons', './main'];
function generateEntries() { function generateEntries() {
// generate automatic entry points // generate automatic entry points
const autoEntries = {}; const autoEntries = {};
const autoEntriesMap = {};
const pageEntries = glob.sync('pages/**/index.js', { const pageEntries = glob.sync('pages/**/index.js', {
cwd: path.join(ROOT_PATH, 'app/assets/javascripts'), cwd: path.join(ROOT_PATH, 'app/assets/javascripts'),
}); });
...@@ -33,14 +34,29 @@ function generateEntries() { ...@@ -33,14 +34,29 @@ function generateEntries() {
function generateAutoEntries(path, prefix = '.') { function generateAutoEntries(path, prefix = '.') {
const chunkPath = path.replace(/\/index\.js$/, ''); const chunkPath = path.replace(/\/index\.js$/, '');
const chunkName = chunkPath.replace(/\//g, '.'); const chunkName = chunkPath.replace(/\//g, '.');
autoEntries[chunkName] = defaultEntries.concat(`${prefix}/${path}`); autoEntriesMap[chunkName] = `${prefix}/${path}`;
} }
pageEntries.forEach(path => generateAutoEntries(path)); pageEntries.forEach(path => generateAutoEntries(path));
autoEntriesCount = Object.keys(autoEntries).length; const autoEntryKeys = Object.keys(autoEntriesMap);
autoEntriesCount = autoEntryKeys.length;
// import ancestor entrypoints within their children
autoEntryKeys.forEach(entry => {
const entryPaths = [autoEntriesMap[entry]];
const segments = entry.split('.');
while (segments.pop()) {
const ancestor = segments.join('.');
if (autoEntryKeys.includes(ancestor)) {
entryPaths.unshift(autoEntriesMap[ancestor]);
}
}
autoEntries[entry] = defaultEntries.concat(entryPaths);
});
const manualEntries = { const manualEntries = {
default: defaultEntries,
raven: './raven/index.js', raven: './raven/index.js',
ide: './ide/index.js', ide: './ide/index.js',
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment