aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack
diff options
context:
space:
mode:
Diffstat (limited to 'config/webpack')
-rw-r--r--config/webpack/loader/dynamic-imports-loader.js31
-rw-r--r--config/webpack/plugins/create-manifest-webpack-plugin/index.js8
2 files changed, 36 insertions, 3 deletions
diff --git a/config/webpack/loader/dynamic-imports-loader.js b/config/webpack/loader/dynamic-imports-loader.js
new file mode 100644
index 0000000..06f9704
--- /dev/null
+++ b/config/webpack/loader/dynamic-imports-loader.js
@@ -0,0 +1,31 @@
+const { ImportManager } = require("import-manager");
+const { getFileNameHash } = webpackRequire("utils/file-name-hash");
+
+const sharedModules = webpackRequire("utils/shared-modules.js");
+
+module.exports = source => {
+ const manager = new ImportManager(source);
+
+ let modified = false;
+
+ for (const unit of manager.imports.es6.units) {
+ const moduleIndex = sharedModules.indexOf(unit.module.name);
+ if (moduleIndex >= 0 && unit.type === "es6") {
+ const importedModuleNames = unit.members.entities
+ .map(entity => `\t${entity.name}`)
+ .concat(unit.defaultMembers.entities.map(entity => `\tdefault: ${entity.name}`))
+ .join(",\n");
+
+ const importStatement = `const {\n${importedModuleNames}\n} = await import(/* webpackIgnore: true */ "/shared/${getFileNameHash(sharedModules[moduleIndex])}.js");\n`;
+
+ unit.methods = {
+ makeUntraceable() {}
+ };
+ manager.remove(unit);
+ manager.insertStatement(importStatement, "bottom", "dynamic");
+ modified = true;
+ }
+ }
+
+ return modified ? manager.code.toString() + "\nexport {};" : source;
+};
diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
index 77f5959..4ab363f 100644
--- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js
+++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
@@ -38,12 +38,14 @@ class CreateManifestPlugin {
const resources = [];
for (const assetName in assets) {
- if (/^assets\/.*\.(jpg|png|gif)$/.test(assetName))
+ if (/^assets\/.*\.(jpg|png|gif)$/.test(assetName)) {
resources.push(assetName);
+ }
}
- for (const sharedModule of sharedModules)
- resources.push(`shared/${sharedModule}.js`);
+ for (const sharedModule of sharedModules) {
+ resources.push(`shared/${getFileNameHash(sharedModule)}.js`);
+ }
if (resources.length > 0) {
manifest.web_accessible_resources = [