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

Path Resolving #53

Closed
Rados51 opened this issue Mar 15, 2022 · 2 comments
Closed

Path Resolving #53

Rados51 opened this issue Mar 15, 2022 · 2 comments

Comments

@Rados51
Copy link

Rados51 commented Mar 15, 2022

It would be cool if we could pass alias object in the same way as define (ladleConfig.define).
Many of my projects depends on path resolving, as I can easily access nested files across project.

If I am not mistaken, the first code block should work just fine, but I've added a second solution as I don't work Vite quite often.
I would try to make a pull request, but I am not sure how to test/load Ladle from the local folder (as yarn add "/path-to-folder" does not work as I thought).

I guess you could add it just to https://github.com/tajo/ladle/blob/master/packages/ladle/lib/cli/vite-base.js and few other places that use ladleConfig.

// https://theroadtoenterprise.com/blog/how-to-set-up-path-resolving-in-vite
// vite.config.js
import { defineConfig } from 'vite';
import path from 'path';

export default defineConfig({
  plugins: [],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@plugins': path.resolve(__dirname, './src/plugins'),
    },
  },
});
// https://stackoverflow.com/questions/68217795/vite-resolve-alias-how-to-resolve-paths
// vite.config.js
import { defineConfig } from 'vite';
import path from 'path';

export default defineConfig({
  resolve: {
    alias: [
      { find: '@', replacement: path.resolve(__dirname, './src') },
      { find: '@plugins', replacement: path.resolve(__dirname, './src/plugins') },
    ]
  }
});
@tajo
Copy link
Owner

tajo commented Mar 15, 2022

Yea, I'm going to expose alias parameter. Is it common to use @ as an alias for src since someone else mentioned that too. If so, it could be a default.

@tajo
Copy link
Owner

tajo commented Mar 16, 2022

Fixed #55

With version 0.8.3, you can now create .ladle/config.mjs and add custom import aliases:

export default {
  resolve: {
    alias: {
      "@": "../src",
    },
  },
};

@tajo tajo closed this as completed Mar 16, 2022
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