0.6.1 • Published 9 months ago
@shopify/async-swc-plugin v0.6.1
shopify_async_swc_plugin
Plugin for @shopify/async
.
This plugin will look for any functions imported from the specified packages. It will then iterate over each reference to that function and, if the reference is a call expression where the first argument is an object, and that object has a load
function, will mark it for processing. The adjustment is simple: it simply adds an id
method that returns a Webpack-specific identifier based on the first dynamic import in the load
method, allowing the function to use this identifier to mark the module as used.
import { createAsyncComponent } from "my-package";
createAsyncComponent({
load: () => import("../SomeComponent"),
});
// Becomes:
createAsyncComponent({
load: () => import("../SomeComponent"),
id: () => require.resolveWeak("../SomeComponent"),
});
Usage
To load plugins, you may use swcrc
's jsc.experimental
configs:
{
jsc: {
...
experimental: {
...
cache_root: String // optional, specify where swc will create wasm bytecode cache
// list of plugins. If `pluginname` is resolvable to npm package, it'll try to load from installed npm packages.
// or it can be an absolute path to the .wasm binary
plugins: [ ['@shopify/async-swc-plugin'] ]
}
}