add legacy extras, so deps only needed for legacy are not in main bundle

This commit is contained in:
Bruno Windels 2020-09-16 18:28:48 +02:00
parent aac67ff890
commit 77a21c08eb
3 changed files with 13 additions and 6 deletions

View file

@ -88,7 +88,7 @@ async function build() {
// so do it first
const themeAssets = await copyThemeAssets(themes, legacy);
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 cssBundlePaths = await buildCssBundles(legacy ? buildCssLegacy : buildCss, themes, themeAssets);
@ -185,7 +185,7 @@ async function buildHtml(doc, version, assetPaths, manifestPath) {
doc("script#main").replaceWith(
`<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>${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);
const versionScript = doc("script#version");
@ -218,7 +218,7 @@ async function buildJs(inputFile, outputName) {
return bundlePath;
}
async function buildJsLegacy(inputFile, outputName, polyfillFile = null) {
async function buildJsLegacy(inputFile, outputName, extraFile, polyfillFile) {
// compile down to whatever IE 11 needs
const babelPlugin = babel.babel({
babelHelpers: 'bundled',
@ -237,9 +237,13 @@ async function buildJsLegacy(inputFile, outputName, polyfillFile = null) {
if (!polyfillFile) {
polyfillFile = 'src/legacy-polyfill.js';
}
const inputFiles = [polyfillFile, inputFile];
if (extraFile) {
inputFiles.push(extraFile);
}
// create js bundle
const rollupConfig = {
input: [polyfillFile, inputFile],
input: inputFiles,
plugins: [multi(), commonjs(), nodeResolve(), babelPlugin, removeJsComments({comments: "none"})]
};
const bundle = await rollup(rollupConfig);
@ -255,7 +259,7 @@ async function buildJsLegacy(inputFile, outputName, polyfillFile = null) {
function buildWorkerJsLegacy(inputFile, outputName) {
const polyfillFile = 'src/worker-polyfill.js';
return buildJsLegacy(inputFile, outputName, polyfillFile);
return buildJsLegacy(inputFile, outputName, null, polyfillFile);
}
async function buildOffline(version, assetPaths) {

3
src/legacy-extras.js Normal file
View file

@ -0,0 +1,3 @@
//import aesjs from "../lib/aes-js/index.js";
let aesjs = "aesjs";
export const legacyExtras = {aesjs};

View file

@ -78,7 +78,7 @@ async function loadOlmWorker(paths) {
// Don't use a default export here, as we use multiple entries during legacy build,
// which does not support default exports,
// 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 {
const isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
if (isIE11) {