DEV: Pass static scripts through Ember CLI (#17373)

All files under `app/assets/javascripts/scripts` will be run through babel, given sourcemaps, and output under `/assets/{name}.js`. This is another step towards removing our sprockets dependence.
This commit is contained in:
David Taylor 2022-07-08 10:13:46 +01:00 committed by GitHub
parent 9dab97de70
commit a084680f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 42 additions and 8 deletions

View File

@ -7,6 +7,7 @@ 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 generateScriptsTree = require("./lib/scripts");
const funnel = require("broccoli-funnel");
module.exports = function (defaults) {
@ -138,5 +139,6 @@ module.exports = function (defaults) {
headerFiles: [`start-app.js`],
inputFiles: [`discourse-boot.js`],
}),
generateScriptsTree(app),
]);
};

View File

@ -0,0 +1,39 @@
const mergeTrees = require("broccoli-merge-trees");
const funnel = require("broccoli-funnel");
const concat = require("broccoli-concat");
const fs = require("fs");
// Each file under `scripts/{name}.js` is run through babel, sourcemapped, and then output to `/assets/{name}.js
module.exports = function scriptsTree(app) {
let babelAddon = app.project.findAddonByName("ember-cli-babel");
let babelConfig = {
babel: { sourceMaps: "inline" },
"ember-cli-babel": { compileModules: false },
};
const trees = [];
const scripts = fs
.readdirSync("scripts", { withFileTypes: true })
.filter((dirent) => dirent.isFile());
for (let script of scripts) {
let source = funnel(`scripts`, {
files: [script.name],
destDir: "scripts",
});
// Babel will append a base64 sourcemap to the file
let transpiled = babelAddon.transpileTree(source, babelConfig);
// We don't actually need to concat any source files... but this will move the base64
// source map into its own file
let transpiledWithDecodedSourcemap = concat(transpiled, {
outputFile: `assets/${script.name}`,
});
trees.push(transpiledWithDecodedSourcemap);
}
return mergeTrees(trees);
};

View File

@ -1,4 +1,3 @@
// discourse-skip-module
(function () {
setTimeout(function () {
const $activateButton = $("#activate-account-button");

View File

@ -1,4 +1,3 @@
// discourse-skip-module
(function () {
const path = document.getElementById("data-auto-redirect").dataset.path;
setTimeout(function () {

View File

@ -1,4 +1,3 @@
// discourse-skip-module
(function () {
const referer = document.getElementById("data-embedded").dataset.referer;

View File

@ -1,4 +1,3 @@
// discourse-skip-module
(function () {
const gtmDataElement = document.getElementById("data-google-tag-manager");
const dataLayerJson = JSON.parse(gtmDataElement.dataset.dataLayer);

View File

@ -1,4 +1,3 @@
// discourse-skip-module
/* eslint-disable */
// prettier-ignore
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@ -1,4 +1,3 @@
// discourse-skip-module
(function () {
const gaDataElement = document.getElementById("data-ga-universal-analytics");
window.dataLayer = window.dataLayer || [];

View File

@ -1,4 +1,3 @@
// discourse-skip-module
window.onpopstate = function (event) {
// check if Discourse object exists if not take care of back navigation
if (event.state && !window.hasOwnProperty("Discourse")) {

View File

@ -9,7 +9,7 @@ module EmberCli
pretty-text-bundle.js
start-discourse.js
vendor.js
)
) + Dir.glob("app/assets/javascripts/discourse/scripts/*.js").map { |f| File.basename(f) }
def self.script_chunks
return @@chunk_infos if defined? @@chunk_infos