diff options
author | Ed Lee <edilee@mozilla.com> | 2019-05-30 07:35:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-30 07:35:16 -0700 |
commit | 51849c91e919490df1aeda0f81fa6b733f9cb98a (patch) | |
tree | 567e423586cd8ee6ec5850512523f976d2a46e9f | |
parent | 685427ad0ef2801120f165850e211a5845cdc53a (diff) |
Bug 1555393 - Remove activity-stream-prerender.jsx and build code (#5081)
-rw-r--r-- | .eslintignore | 1 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | .mcignore | 2 | ||||
-rw-r--r-- | bin/render-activity-stream-html.js | 26 | ||||
-rw-r--r-- | content-src/activity-stream-prerender.jsx | 19 | ||||
-rw-r--r-- | jar.mn | 2 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | webpack.prerender.config.js | 34 | ||||
-rw-r--r-- | yamscripts.yml | 2 |
9 files changed, 8 insertions, 82 deletions
diff --git a/.eslintignore b/.eslintignore index cc80f85d..f7f27c26 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,3 @@ -bin/prerender.js data/ logs/ prerendered/ @@ -12,8 +12,6 @@ data/content/activity-stream.bundle.js data/locales.json css/*.css prerendered/ -bin/prerender.js -bin/prerender.js.map aboutlibrary/content/aboutlibrary.bundle.js aboutlibrary/content/*.map aboutlibrary/content/*.css @@ -7,8 +7,6 @@ npm-debug.log .gitignore /.git/ -/bin/prerender.js -/bin/prerender.js.map /data/locales.json /dist/ /logs/ diff --git a/bin/render-activity-stream-html.js b/bin/render-activity-stream-html.js index 54b1521e..510485da 100644 --- a/bin/render-activity-stream-html.js +++ b/bin/render-activity-stream-html.js @@ -3,9 +3,6 @@ const fs = require("fs"); const {mkdir} = require("shelljs"); const path = require("path"); -// Note: this file is generated by webpack from content-src/activity-stream-prerender.jsx -const {prerender} = require("./prerender"); - const {CENTRAL_LOCALES, DEFAULT_LOCALE} = require("./locales"); // Note: DEFAULT_OPTIONS.baseUrl should match BASE_URL in aboutNewTabService.js @@ -64,11 +61,9 @@ function getTextDirection(locale) { * {str} options.baseUrl The base URL for all local assets * {bool} options.debug Should we use dev versions of JS libraries? * {bool} options.noscripts Should we include scripts in the prerendered files? - * @param {str} html The prerendered HTML created with React.renderToString (optional) * @return {str} An HTML document as a string */ -function templateHTML(options, html) { - const isPrerendered = !!html; +function templateHTML(options) { const debugString = options.debug ? "-dev" : ""; const scripts = [ "chrome://browser/content/contentSearchUI.js", @@ -82,9 +77,6 @@ function templateHTML(options, html) { `${options.baseUrl}prerendered/${options.locale}/activity-stream-strings.js`, `${options.baseUrl}data/content/activity-stream.bundle.js`, ]; - if (isPrerendered) { - scripts.unshift(`${options.baseUrl}prerendered/static/activity-stream-initial-state.js`); - } // Add spacing and script tags const scriptRender = `\n${scripts.map(script => ` <script src="${script}"></script>`).join("\n")}`; @@ -101,7 +93,7 @@ function templateHTML(options, html) { </head> <body class="activity-stream"> <div id="header-asrouter-container" role="presentation"></div> - <div id="root">${isPrerendered ? html : "<!-- Regular React Rendering -->"}</div> + <div id="root"></div> <div id="footer-asrouter-container" role="presentation"></div>${options.noscripts ? "" : scriptRender} </body> </html> @@ -135,25 +127,20 @@ window.${name} = ${JSON.stringify(state, null, 2)}; * @param {string} name Something to identify in the console * @param {string} destPath Path to write the files to * @param {Map} filesMap Mapping of a string file name to templater - * @param {Object} prerenderData Contains the html and state * @param {Object} options Various options for the templater */ -function writeFiles(name, destPath, filesMap, {html, state}, options) { +function writeFiles(name, destPath, filesMap, options) { for (const [file, templater] of filesMap) { - fs.writeFileSync(path.join(destPath, file), templater({html, options, state})); + fs.writeFileSync(path.join(destPath, file), templater({options})); } console.log("\x1b[32m", `✓ ${name}`, "\x1b[0m"); } const STATIC_FILES = new Map([ ["activity-stream-debug.html", ({options}) => templateHTML(options)], - ["activity-stream-initial-state.js", ({state}) => templateJs("gActivityStreamPrerenderedState", "static", state)], - ["activity-stream-prerendered-debug.html", ({html, options}) => templateHTML(options, html)], ]); const LOCALIZED_FILES = new Map([ - ["activity-stream-prerendered.html", ({html, options}) => templateHTML(options, html)], - ["activity-stream-prerendered-noscripts.html", ({html, options}) => templateHTML(Object.assign({}, options, {noscripts: true}), html)], ["activity-stream-strings.js", ({options: {locale, strings}}) => templateJs("gActivityStreamStrings", locale, strings)], ["activity-stream.html", ({options}) => templateHTML(options)], ["activity-stream-noscripts.html", ({options}) => templateHTML(Object.assign({}, options, {noscripts: true}))], @@ -200,7 +187,6 @@ function main() { // eslint-disable-line max-statements continue; } - const prerenderData = prerender(locale, strings); const options = Object.assign({}, baseOptions, { direction: getTextDirection(locale), locale, @@ -210,13 +196,13 @@ function main() { // eslint-disable-line max-statements // Put locale-specific files in their own directory const localePath = path.join(prerenderedPath, "locales", locale); mkdir("-p", localePath); - writeFiles(locale, localePath, LOCALIZED_FILES, prerenderData, options); + writeFiles(locale, localePath, LOCALIZED_FILES, options); // Only write static files once for the default locale if (locale === DEFAULT_LOCALE) { const staticPath = path.join(prerenderedPath, "static"); mkdir("-p", staticPath); - writeFiles(`${locale} (static)`, staticPath, STATIC_FILES, prerenderData, + writeFiles(`${locale} (static)`, staticPath, STATIC_FILES, Object.assign({}, options, {debug: true})); // Save the default strings to compare against other locales' strings diff --git a/content-src/activity-stream-prerender.jsx b/content-src/activity-stream-prerender.jsx deleted file mode 100644 index 8e94a7a2..00000000 --- a/content-src/activity-stream-prerender.jsx +++ /dev/null @@ -1,19 +0,0 @@ -import React from "react"; -import ReactDOMServer from "react-dom/server"; - -export function prerender(locale, strings, - renderToString = ReactDOMServer.renderToString) { - const html = renderToString(<div />); - - // If this happens, it means pre-rendering is effectively disabled, so we - // need to sound the alarms: - if (!html || !html.length) { - throw new Error("no HTML returned"); - } - - return { - html, - state: {}, - store: {getState() {}}, - }; -} @@ -27,9 +27,7 @@ browser.jar: #else res/activity-stream/css/activity-stream.css (./css/activity-stream-linux.css) #endif - res/activity-stream/prerendered/static/activity-stream-initial-state.js (./prerendered/static/activity-stream-initial-state.js) #ifndef RELEASE_OR_BETA res/activity-stream/prerendered/static/activity-stream-debug.html (./prerendered/static/activity-stream-debug.html) - res/activity-stream/prerendered/static/activity-stream-prerendered-debug.html (./prerendered/static/activity-stream-prerendered-debug.html) #endif res/activity-stream/prerendered/ (./prerendered/locales/*) diff --git a/package.json b/package.json index ce6fce0c..2dc57dd2 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "bundle:locales": "pontoon-to-json --src $npm_package_config_locales_dir --dest data", "bundle:webpack": "webpack --config webpack.system-addon.config.js", "bundle:css": "node-sass content-src/styles -o css", - "bundle:html": "rimraf prerendered && webpack --config webpack.prerender.config.js && node ./bin/render-activity-stream-html.js", + "bundle:html": "rimraf prerendered && node ./bin/render-activity-stream-html.js", "buildmc": "npm-run-all buildmc:*", "prebuildmc": "rimraf $npm_package_config_mc_dir/browser/components/newtab/", "buildmc:bundle": "npm run bundle", diff --git a/webpack.prerender.config.js b/webpack.prerender.config.js deleted file mode 100644 index 84b2b091..00000000 --- a/webpack.prerender.config.js +++ /dev/null @@ -1,34 +0,0 @@ -const path = require("path"); -const webpackConfig = require("./webpack.system-addon.config"); -const webpack = require("webpack"); - -const srcPath = "content-src/activity-stream-prerender.jsx"; - -const banner = ` -NOTE: This file is generated by webpack from ${srcPath} -using the buildmc:html npm task. -`; - -module.exports = Object.assign({}, webpackConfig(), { - mode: "none", - target: "node", - devtool: "sourcemap", - entry: path.join(__dirname, srcPath), - output: { - path: path.join(__dirname, "bin"), - filename: "prerender.js", - libraryTarget: "commonjs2", - }, - externals: { - "prop-types": "commonjs prop-types", - "react": "commonjs react", - "react-dom": "commonjs react-dom", - }, - plugins: [ - new webpack.BannerPlugin(banner), - // fluent-react is expecting a browser environment and `document` is not - // available in our prerendering step. - // https://github.com/projectfluent/fluent.js/blob/2f10bdef682b6e9dad482d96ebaaeec9f7631bb9/fluent-react/src/markup.js#L3 - new webpack.DefinePlugin({document: {createElement: () => {}}}), - ], -}); diff --git a/yamscripts.yml b/yamscripts.yml index 3ca3c9ce..3fbc0a06 100644 --- a/yamscripts.yml +++ b/yamscripts.yml @@ -17,7 +17,7 @@ scripts: locales: pontoon-to-json --src $npm_package_config_locales_dir --dest data webpack: webpack --config webpack.system-addon.config.js css: node-sass content-src/styles -o css - html: rimraf prerendered && webpack --config webpack.prerender.config.js && node ./bin/render-activity-stream-html.js + html: rimraf prerendered && node ./bin/render-activity-stream-html.js # buildmc: Export code to mozilla central buildmc: |