mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
add legacy extras, so deps only needed for legacy are not in main bundle
This commit is contained in:
parent
aac67ff890
commit
77a21c08eb
@ -88,7 +88,7 @@ async function build() {
|
|||||||
// so do it first
|
// so do it first
|
||||||
const themeAssets = await copyThemeAssets(themes, legacy);
|
const themeAssets = await copyThemeAssets(themes, legacy);
|
||||||
const jsBundlePath = await buildJs("src/main.js", `${PROJECT_ID}.js`);
|
const jsBundlePath = await buildJs("src/main.js", `${PROJECT_ID}.js`);
|
||||||
const jsLegacyBundlePath = await buildJsLegacy("src/main.js", `${PROJECT_ID}-legacy.js`);
|
const jsLegacyBundlePath = await buildJsLegacy("src/main.js", `${PROJECT_ID}-legacy.js`, 'src/legacy-extras.js');
|
||||||
const jsWorkerPath = await buildWorkerJsLegacy("src/worker.js", `worker.js`);
|
const jsWorkerPath = await buildWorkerJsLegacy("src/worker.js", `worker.js`);
|
||||||
const cssBundlePaths = await buildCssBundles(legacy ? buildCssLegacy : buildCss, themes, themeAssets);
|
const cssBundlePaths = await buildCssBundles(legacy ? buildCssLegacy : buildCss, themes, themeAssets);
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ async function buildHtml(doc, version, assetPaths, manifestPath) {
|
|||||||
doc("script#main").replaceWith(
|
doc("script#main").replaceWith(
|
||||||
`<script type="module">import {main} from "./${assetPaths.jsBundle()}"; main(document.body, ${pathsJSON});</script>` +
|
`<script type="module">import {main} from "./${assetPaths.jsBundle()}"; main(document.body, ${pathsJSON});</script>` +
|
||||||
`<script type="text/javascript" nomodule src="${assetPaths.jsLegacyBundle()}"></script>` +
|
`<script type="text/javascript" nomodule src="${assetPaths.jsLegacyBundle()}"></script>` +
|
||||||
`<script type="text/javascript" nomodule>${PROJECT_ID}Bundle.main(document.body, ${pathsJSON});</script>`);
|
`<script type="text/javascript" nomodule>${PROJECT_ID}Bundle.main(document.body, ${pathsJSON}, ${PROJECT_ID}Bundle.legacyExtras);</script>`);
|
||||||
removeOrEnableScript(doc("script#service-worker"), offline);
|
removeOrEnableScript(doc("script#service-worker"), offline);
|
||||||
|
|
||||||
const versionScript = doc("script#version");
|
const versionScript = doc("script#version");
|
||||||
@ -218,7 +218,7 @@ async function buildJs(inputFile, outputName) {
|
|||||||
return bundlePath;
|
return bundlePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildJsLegacy(inputFile, outputName, polyfillFile = null) {
|
async function buildJsLegacy(inputFile, outputName, extraFile, polyfillFile) {
|
||||||
// compile down to whatever IE 11 needs
|
// compile down to whatever IE 11 needs
|
||||||
const babelPlugin = babel.babel({
|
const babelPlugin = babel.babel({
|
||||||
babelHelpers: 'bundled',
|
babelHelpers: 'bundled',
|
||||||
@ -237,9 +237,13 @@ async function buildJsLegacy(inputFile, outputName, polyfillFile = null) {
|
|||||||
if (!polyfillFile) {
|
if (!polyfillFile) {
|
||||||
polyfillFile = 'src/legacy-polyfill.js';
|
polyfillFile = 'src/legacy-polyfill.js';
|
||||||
}
|
}
|
||||||
|
const inputFiles = [polyfillFile, inputFile];
|
||||||
|
if (extraFile) {
|
||||||
|
inputFiles.push(extraFile);
|
||||||
|
}
|
||||||
// create js bundle
|
// create js bundle
|
||||||
const rollupConfig = {
|
const rollupConfig = {
|
||||||
input: [polyfillFile, inputFile],
|
input: inputFiles,
|
||||||
plugins: [multi(), commonjs(), nodeResolve(), babelPlugin, removeJsComments({comments: "none"})]
|
plugins: [multi(), commonjs(), nodeResolve(), babelPlugin, removeJsComments({comments: "none"})]
|
||||||
};
|
};
|
||||||
const bundle = await rollup(rollupConfig);
|
const bundle = await rollup(rollupConfig);
|
||||||
@ -255,7 +259,7 @@ async function buildJsLegacy(inputFile, outputName, polyfillFile = null) {
|
|||||||
|
|
||||||
function buildWorkerJsLegacy(inputFile, outputName) {
|
function buildWorkerJsLegacy(inputFile, outputName) {
|
||||||
const polyfillFile = 'src/worker-polyfill.js';
|
const polyfillFile = 'src/worker-polyfill.js';
|
||||||
return buildJsLegacy(inputFile, outputName, polyfillFile);
|
return buildJsLegacy(inputFile, outputName, null, polyfillFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildOffline(version, assetPaths) {
|
async function buildOffline(version, assetPaths) {
|
||||||
|
3
src/legacy-extras.js
Normal file
3
src/legacy-extras.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
//import aesjs from "../lib/aes-js/index.js";
|
||||||
|
let aesjs = "aesjs";
|
||||||
|
export const legacyExtras = {aesjs};
|
@ -78,7 +78,7 @@ async function loadOlmWorker(paths) {
|
|||||||
// Don't use a default export here, as we use multiple entries during legacy build,
|
// Don't use a default export here, as we use multiple entries during legacy build,
|
||||||
// which does not support default exports,
|
// which does not support default exports,
|
||||||
// see https://github.com/rollup/plugins/tree/master/packages/multi-entry
|
// see https://github.com/rollup/plugins/tree/master/packages/multi-entry
|
||||||
export async function main(container, paths) {
|
export async function main(container, paths, legacyExtras) {
|
||||||
try {
|
try {
|
||||||
const isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
|
const isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
|
||||||
if (isIE11) {
|
if (isIE11) {
|
||||||
|
Loading…
Reference in New Issue
Block a user