Skip to content

importing 'additionalPaths'? #78

Answered by ElMassimo
GabrielMahan asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Gabriel!

As it's mentioned in the Aliases section of the docs, the ~ prefix is an alias to your sourceCodeDir, which in your case is app/javascript.

You have a few options to reference an outside file:

  • Using relative paths: 👎 error-prone and breaks if you move the file
  • Using relative paths with the root alias as in ~/../assets: 👎 harder to understand
  • Adding an alias in vite.config.ts

I'd recommend adding an alias in your vite.config.ts:

import { resolve } from 'path'
import { defineConfig } from 'vite'

export default defineConfig({
  resolve: {
    alias: {
      '@assets': resolve(__dirname, 'app/assets'),
    },
  },

There is a very similar alias being used in this example setup.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ElMassimo
Comment options

@GabrielMahan
Comment options

Answer selected by ElMassimo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants