Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relative path is wrong when fileName contains a directory #14

Closed
ArloL opened this issue Aug 10, 2023 · 2 comments
Closed

relative path is wrong when fileName contains a directory #14

ArloL opened this issue Aug 10, 2023 · 2 comments

Comments

@ArloL
Copy link

ArloL commented Aug 10, 2023

Thank you so much for creating this plugin.

I create two different output directories for the different two formats es and cjs. I got the idea from
https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html

This is the config I am using right now:

…
export default defineConfig({
  plugins: [
    …
    libAssetsPlugin({
      limit: 1024 * 8,
      extensions: ['.jpg', '.png', '.otf', '.ttf', '.woff'],
    }),
  ],
  build: {
    lib: {
      entry: path.resolve(__dirname, 'src/index.js'),
      formats: ['es', 'cjs'],
      fileName: (format) => {
        if (format === 'es') {
          return 'mjs/index.js';
        }
        return `${format}/index.js`;
      },
    },
    …
  },
});

Sadly the asset path is kept at ./assets in the index.js files. I now added a build step that copies the assets into the mjs and cjs directories. Is there any chance that you might be able to change the imports to ../assets instead?

@ArloL ArloL changed the title relative path is wrong in library mode with fileName containing a directory relative path is wrong when fileName contains a directory Aug 10, 2023
coder-layne added a commit that referenced this issue Aug 10, 2023
coder-layne added a commit that referenced this issue Aug 10, 2023
coder-layne added a commit that referenced this issue Aug 10, 2023
@coder-layne
Copy link
Contributor

Thank you for your feedback. The plugin will adjust the extracted resource's address according to the importer's output path from v0.4.2.

@ArloL
Copy link
Author

ArloL commented Aug 13, 2023

I just tried 0.4.3 and it works. Thank you very much. For me this issue can be closed ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants