AutoImport function is provided by unImport, you can add dependencies for auto import in sword.config.ts, for example, I export a library function like this:
In the ts file, you'll be able to use sendError directly without having to import it manually; this is important for functions that frequently require manual import, such as useApi, so sword.js-cli has a bunch of automatic import APIs built in:
And the auto-import.d.ts file will be generated as a type hint under the src folder each time dev is executed.
Since the dev environment of sword.js is using esbuild-register to open a new sub-process to execute functions, and also enjoy auto-import, we changed the source code of esbuild-register because we want to keep the dev and prod development experience consistent
AutoImport function is provided by
unImport
, you can add dependencies for auto import insword.config.ts
, for example, I export a library function like this:In the ts file, you'll be able to use
sendError
directly without having to import it manually; this is important for functions that frequently require manual import, such asuseApi
, so sword.js-cli has a bunch of automatic import APIs built in:This allows us to quickly write code like this:
And the
auto-import.d.ts
file will be generated as a type hint under the src folder each timedev
is executed.Since the dev environment of sword.js is using esbuild-register to open a new sub-process to execute functions, and also enjoy auto-import, we changed the source code of
esbuild-register
because we want to keep the dev and prod development experience consistent