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.