Skip to content

A platform for community discussion. Free, open, simple.

DEV: invert admin/wizard build logic (#22520)

Godfrey Chan3d7cca591113
diff --git a/app/assets/javascripts/admin/index.js b/app/assets/javascripts/admin/index.js
index 02238e5b63c..8889660fdb5 100644
--- a/app/assets/javascripts/admin/index.js
+++ b/app/assets/javascripts/admin/index.js
@@ -1,15 +1,26 @@
"use strict";
const calculateCacheKeyForTree = require("calculate-cache-key-for-tree");
+const path = require("path");
module.exports = {
name: require("./package").name,
- treeForAddon(tree) {
- let app = this._findHost();
- app.options.adminTree = this._super.treeForAddon.call(this, tree);
+
+ // return an empty tree here as we do not want the addon modules to be
+ // included into vendor.js; instead, we will produce a separate bundle
+ // (admin.js) to be included via a script tag as needed
+ treeForAddon() {
return;
},
+ // custom method to produce the tree for admin.js
+ // called by ember-cli-build.js in discourse core
+ treeForAddonBundle() {
+ let addonTreePath = path.resolve(this.root, this.treePaths.addon);
+ let addonTree = this.treeGenerator(addonTreePath);
+ return this._super.treeForAddon.call(this, addonTree);
+ },
+
cacheKeyForTree(tree) {
return calculateCacheKeyForTree(tree, this);
},
diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.js
index 76e64b6906e..bdc90104bdc 100644
--- a/app/assets/javascripts/discourse/ember-cli-build.js
+++ b/app/assets/javascripts/discourse/ember-cli-build.js
@@ -182,6 +182,10 @@ module.exports = function (defaults) {
.findAddonByName("discourse-plugins")
.generatePluginsTree();
+ const adminTree = app.project.findAddonByName("admin").treeForAddonBundle();
+
+ const wizardTree = app.project.findAddonByName("wizard").treeForAddonBundle();
+
const terserPlugin = app.project.findAddonByName("ember-cli-terser");
const applyTerser = (tree) => terserPlugin.postprocessTree("all", tree);
@@ -196,13 +200,13 @@ module.exports = function (defaults) {
}),
generateWorkboxTree(),
applyTerser(
- concat(mergeTrees([app.options.adminTree]), {
+ concat(adminTree, {
inputFiles: ["**/*.js"],
outputFile: `assets/admin.js`,
})
),
applyTerser(
- concat(mergeTrees([app.options.wizardTree]), {
+ concat(wizardTree, {
inputFiles: ["**/*.js"],
outputFile: `assets/wizard.js`,
})
diff --git a/app/assets/javascripts/wizard/index.js b/app/assets/javascripts/wizard/index.js
index f29529cc51a..afc67ba45b9 100644
--- a/app/assets/javascripts/wizard/index.js
+++ b/app/assets/javascripts/wizard/index.js
@@ -1,15 +1,26 @@
"use strict";
const calculateCacheKeyForTree = require("calculate-cache-key-for-tree");
+const path = require("path");
module.exports = {
name: require("./package").name,
- treeForAddon(tree) {
- let app = this._findHost();
- app.options.wizardTree = this._super.treeForAddon.call(this, tree);
+
+ // return an empty tree here as we do not want the addon modules to be
+ // included into vendor.js; instead, we will produce a separate bundle
+ // (wizard.js) to be included via a script tag as needed
+ treeForAddon() {
return;
},
+ // custom method to produce the tree for wizard.js
+ // called by ember-cli-build.js in discourse core
+ treeForAddonBundle() {
+ let addonTreePath = path.resolve(this.root, this.treePaths.addon);
+ let addonTree = this.treeGenerator(addonTreePath);
+ return this._super.treeForAddon.call(this, addonTree);
+ },
+
cacheKeyForTree(tree) {
return calculateCacheKeyForTree(tree, this);
},