nuxt / module-builder

Complete solution to build and ship Nuxt modules.
MIT License
212 stars 22 forks source link

How to expose files that could be imported as is? #158

Closed existe-deja closed 10 months ago

existe-deja commented 10 months ago

Hi,

I need to centralize come constant files for locale definitions. I need those files to be available before runtime because I need them to specify my nuxt.config file.

Before the module template I built them wth a custom rollup script and exposed them in my package.json file. Now I don't really know how to do it.

To be explicit I want to do something like:

import { localeCodes } from '@my-org/my-module'

Thanks

danielroe commented 10 months ago

You can move them into ~/src/runtime.

existe-deja commented 10 months ago

Ok but by default the build only expose the module file, should I update the package.json exports ?

existe-deja commented 10 months ago

I figured out why it wasn't working. I was using yarn link to simulate the installation and I didn't build the module so the dist files weren't correctly exposed.

existe-deja commented 10 months ago

Well it's not fully solved as vscode still warns me

Cannot find module '@my-org/my-module/i18n' or its corresponding type declarations

import { localeCodes } from '@my-org/my-module/i18n

But in my package.json of the module I have:

"exports": {
    ".": {
      "types": "./dist/types.d.ts",
      "import": "./dist/module.mjs",
      "require": "./dist/module.cjs"
    },
    "./i18n": {
      "types": "./dist/runtime/i18n/config/index.d.ts",
      "import": "./dist/runtime/i18n/config/index.mjs"
    }
  }

The project starts but the vscode error is still present. What am I missing? :thinking:

danielroe commented 10 months ago

The issue you're facing is that you probably have the old legacy TS module resolution mode still active. In a Nuxt project, you can set experimental.typescriptBundlerResolution to true.