mirror of
https://github.com/discourse/discourse.git
synced 2025-06-18 01:02:31 +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:
@ -7,6 +7,7 @@ const concat = require("broccoli-concat");
|
|||||||
const prettyTextEngine = require("./lib/pretty-text-engine");
|
const prettyTextEngine = require("./lib/pretty-text-engine");
|
||||||
const { createI18nTree } = require("./lib/translation-plugin");
|
const { createI18nTree } = require("./lib/translation-plugin");
|
||||||
const discourseScss = require("./lib/discourse-scss");
|
const discourseScss = require("./lib/discourse-scss");
|
||||||
|
const generateScriptsTree = require("./lib/scripts");
|
||||||
const funnel = require("broccoli-funnel");
|
const funnel = require("broccoli-funnel");
|
||||||
|
|
||||||
module.exports = function (defaults) {
|
module.exports = function (defaults) {
|
||||||
@ -138,5 +139,6 @@ module.exports = function (defaults) {
|
|||||||
headerFiles: [`start-app.js`],
|
headerFiles: [`start-app.js`],
|
||||||
inputFiles: [`discourse-boot.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 () {
|
(function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
const $activateButton = $("#activate-account-button");
|
const $activateButton = $("#activate-account-button");
|
@ -1,4 +1,3 @@
|
|||||||
// discourse-skip-module
|
|
||||||
(function () {
|
(function () {
|
||||||
const path = document.getElementById("data-auto-redirect").dataset.path;
|
const path = document.getElementById("data-auto-redirect").dataset.path;
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
@ -1,4 +1,3 @@
|
|||||||
// discourse-skip-module
|
|
||||||
(function () {
|
(function () {
|
||||||
const referer = document.getElementById("data-embedded").dataset.referer;
|
const referer = document.getElementById("data-embedded").dataset.referer;
|
||||||
|
|
@ -1,4 +1,3 @@
|
|||||||
// discourse-skip-module
|
|
||||||
(function () {
|
(function () {
|
||||||
const gtmDataElement = document.getElementById("data-google-tag-manager");
|
const gtmDataElement = document.getElementById("data-google-tag-manager");
|
||||||
const dataLayerJson = JSON.parse(gtmDataElement.dataset.dataLayer);
|
const dataLayerJson = JSON.parse(gtmDataElement.dataset.dataLayer);
|
@ -1,4 +1,3 @@
|
|||||||
// discourse-skip-module
|
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
@ -1,4 +1,3 @@
|
|||||||
// discourse-skip-module
|
|
||||||
(function () {
|
(function () {
|
||||||
const gaDataElement = document.getElementById("data-ga-universal-analytics");
|
const gaDataElement = document.getElementById("data-ga-universal-analytics");
|
||||||
window.dataLayer = window.dataLayer || [];
|
window.dataLayer = window.dataLayer || [];
|
@ -1,4 +1,3 @@
|
|||||||
// discourse-skip-module
|
|
||||||
window.onpopstate = function (event) {
|
window.onpopstate = function (event) {
|
||||||
// check if Discourse object exists if not take care of back navigation
|
// check if Discourse object exists if not take care of back navigation
|
||||||
if (event.state && !window.hasOwnProperty("Discourse")) {
|
if (event.state && !window.hasOwnProperty("Discourse")) {
|
@ -9,7 +9,7 @@ module EmberCli
|
|||||||
pretty-text-bundle.js
|
pretty-text-bundle.js
|
||||||
start-discourse.js
|
start-discourse.js
|
||||||
vendor.js
|
vendor.js
|
||||||
)
|
) + Dir.glob("app/assets/javascripts/discourse/scripts/*.js").map { |f| File.basename(f) }
|
||||||
|
|
||||||
def self.script_chunks
|
def self.script_chunks
|
||||||
return @@chunk_infos if defined? @@chunk_infos
|
return @@chunk_infos if defined? @@chunk_infos
|
||||||
|
Reference in New Issue
Block a user