Skip to content

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

DEV: Allow `ember server --environment production` to be used (#15431)

David Taylor7fdb2944b9ea
diff --git a/app/assets/javascripts/discourse/config/environment.js b/app/assets/javascripts/discourse/config/environment.js
index f9672557d97..41568254493 100644
--- a/app/assets/javascripts/discourse/config/environment.js
+++ b/app/assets/javascripts/discourse/config/environment.js
@@ -17,6 +17,7 @@ module.exports = function (environment) {
Date: false,
},
},
+ exportApplicationGlobal: true,
APP: {
// Here you can pass flags/options to your application instance
diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.js
index d7bd432bdb3..5125e7e08e5 100644
--- a/app/assets/javascripts/discourse/ember-cli-build.js
+++ b/app/assets/javascripts/discourse/ember-cli-build.js
@@ -28,15 +28,17 @@ module.exports = function (defaults) {
autoImport: {
forbidEval: true,
},
+ fingerprint: {
+ // Disabled here, but handled manually below when in production mode.
+ // This is so we can apply a single AssetRev operation over the application and our additional trees
+ enabled: false,
+ },
+ SRI: {
+ // We don't use SRI in Rails. Disable here to match:
+ enabled: false,
+ },
});
- // Ember CLI does this by default for the app tree, but for our extra bundles we
- // need to do it ourselves in production mode.
- const isProduction = EmberApp.env().includes("production");
- function digest(tree) {
- return isProduction ? new AssetRev(tree) : tree;
- }
-
// WARNING: We should only import scripts here if they are not in NPM.
// For example: our very specific version of bootstrap-modal.
app.import(vendorJs + "bootbox.js");
@@ -48,7 +50,7 @@ module.exports = function (defaults) {
});
app.import(discourseRoot + "/app/assets/javascripts/polyfills.js");
- return mergeTrees([
+ const mergedTree = mergeTrees([
discourseScss(`${discourseRoot}/app/assets/stylesheets`, "testem.scss"),
createI18nTree(discourseRoot, vendorJs),
app.toTree(),
@@ -57,18 +59,28 @@ module.exports = function (defaults) {
files: ["highlight-test-bundle.min.js"],
destDir: "assets/highlightjs",
}),
- digest(
- concat(mergeTrees([app.options.adminTree]), {
- outputFile: `assets/admin.js`,
- })
- ),
- digest(prettyTextEngine(vendorJs, "discourse-markdown")),
- digest(
- concat("public/assets/scripts", {
- outputFile: `assets/start-discourse.js`,
- headerFiles: [`start-app.js`],
- inputFiles: [`discourse-boot.js`],
- })
- ),
+ concat(mergeTrees([app.options.adminTree]), {
+ outputFile: `assets/admin.js`,
+ }),
+ prettyTextEngine(vendorJs, "discourse-markdown"),
+ concat("public/assets/scripts", {
+ outputFile: `assets/start-discourse.js`,
+ headerFiles: [`start-app.js`],
+ inputFiles: [`discourse-boot.js`],
+ }),
]);
+
+ const isProduction = EmberApp.env().includes("production");
+ if (isProduction) {
+ return new AssetRev(mergedTree, {
+ exclude: [
+ "javascripts/**/*",
+ "assets/test-i18n*",
+ "assets/highlightjs",
+ "assets/testem.css",
+ ],
+ });
+ } else {
+ return mergedTree;
+ }
};