Running in production mode is useful when doing performance-sensitive work. - Set the `exportApplicationGlobal` flag, so we get the `Discourse` global in production mode. It defaults to only adding the global in development mode. Note that, when generating ember-cli assets via rails, we set this in `ApplicationHelper#discourse_config_environment`. - Disable SRI - Ember CLI adds this to index.html when in production mode. We don't use SRI in production, so disable here to match. - Refactor the `AssetRev` logic in `ember-cli-build.js`, so that our custom bundle hashes are find/replaced into index.html. Without this change, our custom bundles (e.g. `start-discourse.js`) remain without their hash in `index.html`, and do not function. I have confirmed that the only diff in the `/dist` out following this change is to the `index.html` file. All other filenames and contents remain identical.
87 lines
2.9 KiB
JavaScript
87 lines
2.9 KiB
JavaScript
"use strict";
|
|
|
|
const EmberApp = require("ember-cli/lib/broccoli/ember-app");
|
|
const resolve = require("path").resolve;
|
|
const mergeTrees = require("broccoli-merge-trees");
|
|
const concat = require("broccoli-concat");
|
|
const prettyTextEngine = require("./lib/pretty-text-engine");
|
|
const { createI18nTree } = require("./lib/translation-plugin");
|
|
const discourseScss = require("./lib/discourse-scss");
|
|
const funnel = require("broccoli-funnel");
|
|
const AssetRev = require("broccoli-asset-rev");
|
|
|
|
module.exports = function (defaults) {
|
|
let discourseRoot = resolve("../../../..");
|
|
let vendorJs = discourseRoot + "/vendor/assets/javascripts/";
|
|
|
|
let app = new EmberApp(defaults, {
|
|
autoRun: false,
|
|
"ember-qunit": {
|
|
insertContentForTestBody: false,
|
|
},
|
|
sourcemaps: {
|
|
// There seems to be a bug with brocolli-concat when sourcemaps are disabled
|
|
// that causes the `app.import` statements below to fail in production mode.
|
|
// This forces the use of `fast-sourcemap-concat` which works in production.
|
|
enabled: true,
|
|
},
|
|
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,
|
|
},
|
|
});
|
|
|
|
// 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");
|
|
app.import(vendorJs + "bootstrap-modal.js");
|
|
app.import(vendorJs + "jquery.ui.widget.js");
|
|
app.import(vendorJs + "caret_position.js");
|
|
app.import("node_modules/ember-source/dist/ember-template-compiler.js", {
|
|
type: "test",
|
|
});
|
|
app.import(discourseRoot + "/app/assets/javascripts/polyfills.js");
|
|
|
|
const mergedTree = mergeTrees([
|
|
discourseScss(`${discourseRoot}/app/assets/stylesheets`, "testem.scss"),
|
|
createI18nTree(discourseRoot, vendorJs),
|
|
app.toTree(),
|
|
funnel(`${discourseRoot}/public/javascripts`, { destDir: "javascripts" }),
|
|
funnel(`${vendorJs}/highlightjs`, {
|
|
files: ["highlight-test-bundle.min.js"],
|
|
destDir: "assets/highlightjs",
|
|
}),
|
|
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;
|
|
}
|
|
};
|