Open AndreyYolkin opened 2 years ago
Nice idea to support option. BTW have you tried adding a build.config
to add custom externals?
No, because I didn't find any mentions about build.config
. Gonna try and answer later about it 💪
Nice idea to support option. BTW have you tried adding a
build.config
to add custom externals?
Yes, I added build.config.ts
in the module package root and specified own externals in it. And it works. I think, that information about extra configuration should be provided in README
I had a very similar issue that I have been tackling for the past several days.
Defining the problematic module in build.config
as an external helped me resolve it.
+1 for this to be provided in a README.
Would it be possible to share an example build.config.ts
configuration, where extra externals are added while we wait for it to be added to the README? :eyes:
In my case the defu package was the issue and preventing me to release.
Add build.config.ts to your root directory and fill it with `import { defineBuildConfig } from 'unbuild'
export default defineBuildConfig({ externals: [ 'defu', ], }) `
You can also see the build.config.ts in the root of this project https://github.com/nuxt/module-builder/blob/main/build.config.ts
The right solution in most cases is adding the packages concerned to your package.json as either dependencies or peerDependencies. If your module is going to use them or import them, they should be declared as dependencies.
Specifying externals manually is an escape hatch and should be used with caution.
Ah thanks for the info. I just added defu to "dependencies" (it was missing somehow) and the build warning was gone withouth any extra build config 💯
Here is an example of how to configure it in a build.config:
https://github.com/nuxt/nuxt/blob/main/packages/schema/build.config.ts#L21
@danielroe Is there a way to tell the module-builder to transpile a dependency?
We have a monorepo with a utils package written in Typescript. One of the functions is imported from a .ts
file into the module. When building the module this leads to an error. I'd like to explicitly include the file in the final bundle somehow, without having to bundle the utils package prior.
Let's imagine that I'm creating some helpers which I want to use in my modules definition. Some of them so specific and never will be included in @nuxt/kit, but I use some kit methods to create them.
Just an example:
This function relies on
@nuxt/kit
anddefu
and if I define it in module definition, module builds successfully, but after moving this snippet to another package (e.g.@yolkin/config
)@nuxt/module-builder
tries to inline lots of files, because@yolkin/config
is not listed in externals: https://github.com/nuxt/module-builder/blob/6453ed0bc104f7ef167f9f16bc012968d1b9261d/src/build.ts#L31-L41So, I want to have an ability to extend externals to have an ability to build my modules with extended functions without inlining the whole nuxt inside of it.