Iâve figured out a solution that works with multiple app blocks. I edited the rollup.config.js and .liquid files slightly and am using the SystemJS loader.
First, create your new app block and corresponding JavaScript file. For the sake of this tutorial, letâs call the new app block âblock2.liquidâ and corresponding JavaScript file âapp2.jsâ.
Then, edit your rollup.config.js to look like:
import commonjs from "@rollup/plugin-commonjs";
import copy from "rollup-plugin-copy";
const input = {
app: "./assets/app.js",
app2: "./assets/app2.js",
};
export default {
input,
output: {
dir: "../../extensions/code-splitting-example/assets",
format: "system",
},
plugins: [
commonjs(),
copy({
targets: [
{ src: "./assets/*.css", dest: "../../extensions/code-splitting-example/assets" },
{ src: "./assets/system.js", dest: "../../extensions/code-splitting-example/assets" },
{
src: "./blocks/*.liquid",
dest: "../../extensions/code-splitting-example/blocks",
},
],
}),
],
};
You can see I made 3 changes: I added the path to the new JavaScript file associated with my second app block ("./assets/app2.js), I set the output format to âsystemâ so that it uses the SystemJS format, and I added a copy target which copies a new âsystem.jsâ file to my âextensionsâ directory.
To download this new system.js file, go to the SystemJS Readme - Overview, and download the loader of your choosing. I chose the regular system.js loader (option 2). Then, rename the downloaded file to âsystem.jsâ, and place it in the folder âdev-extensions/code-splitting-example/assetsâ.
In each of your .liquid files, paste the following code at the top (replace âapp2.jsâ in the code below with whatever you called the JavaScript file associated with your given app block):
After making the above changes, running npm run build in the âdev-extensions/code-splitting-exampleâ directory should generate files in a format that still works with Shopify Theme App Extensions, even when you have multiple app blocks.