mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
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:
parent
9dab97de70
commit
a084680f1d
|
@ -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),
|
||||
]);
|
||||
};
|
||||
|
|
39
app/assets/javascripts/discourse/lib/scripts.js
Normal file
39
app/assets/javascripts/discourse/lib/scripts.js
Normal 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);
|
||||
};
|
|
@ -1,4 +1,3 @@
|
|||
// discourse-skip-module
|
||||
(function () {
|
||||
setTimeout(function () {
|
||||
const $activateButton = $("#activate-account-button");
|
|
@ -1,4 +1,3 @@
|
|||
// discourse-skip-module
|
||||
(function () {
|
||||
const path = document.getElementById("data-auto-redirect").dataset.path;
|
||||
setTimeout(function () {
|
|
@ -1,4 +1,3 @@
|
|||
// discourse-skip-module
|
||||
(function () {
|
||||
const referer = document.getElementById("data-embedded").dataset.referer;
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
// discourse-skip-module
|
||||
(function () {
|
||||
const gtmDataElement = document.getElementById("data-google-tag-manager");
|
||||
const dataLayerJson = JSON.parse(gtmDataElement.dataset.dataLayer);
|
|
@ -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(){
|
|
@ -1,4 +1,3 @@
|
|||
// discourse-skip-module
|
||||
(function () {
|
||||
const gaDataElement = document.getElementById("data-ga-universal-analytics");
|
||||
window.dataLayer = window.dataLayer || [];
|
|
@ -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")) {
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user