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

docs(config-file): update tip note about string replace #7846

Merged
merged 1 commit into from
May 9, 2022

Conversation

jprando
Copy link
Contributor

@jprando jprando commented Apr 21, 2022

Description

in the documentation, guide developers about errors that may occur in certain use cases, referring to the vite configuration file

Additional context

reproducing:

  • start a new project with vite + vue + ts
  • insert console.log("import.meta.url") at the end of the vite.config.ts file
  • build the project

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red added the documentation Improvements or additions to documentation label Apr 26, 2022
@sapphi-red
Copy link
Member

@jprando https://stackblitz.com/edit/vitejs-vite-bme6zd?file=vite.config.ts&terminal=dev
I was not able to reproduce it. Am i missing something?

@jprando
Copy link
Contributor Author

jprando commented May 5, 2022

@jprando https://stackblitz.com/edit/vitejs-vite-bme6zd?file=vite.config.ts&terminal=dev I was not able to reproduce it. Am i missing something?

forward this asciinema

https://asciinema.org/a/492422

look for double quote in console.log

@jprando
Copy link
Contributor Author

jprando commented May 5, 2022

@jprando https://stackblitz.com/edit/vitejs-vite-bme6zd?file=vite.config.ts&terminal=dev I was not able to reproduce it. Am i missing something?

double quote here and the error occurs

image

@bluwy
Copy link
Member

bluwy commented May 5, 2022

I can reproduce it too with double quotes. On the other hand, I wonder if we should change the strategy to polyfill using globals instead 🤔

globalThis.import = { url: "bla" }
globalThis.__dirname = "bla"

@sapphi-red
Copy link
Member

sapphi-red commented May 6, 2022

Global variables nor define cannot be used because the value differs among files.

// foo.js
export const myFile = __filename

// -----------
// vite.config.js
const { myFile: myFileFoo } = require('./foo.js')
const myFile = __filename

console.log(myFileFoo) // 'foo.js'
console.log(myFile) // 'vite.config.js'

@bluwy
Copy link
Member

bluwy commented May 9, 2022

That's true, maybe we can inject them at the top of the file as variables, but now I'm also leaning to not polyfilling them at all to keep it closer to specs. And with Vite 3 around the corner, we can group all config issues and make one breaking change 🤔

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge this in the meantime. We may end up removing this section in v3 but it is ok to have it for the moment.

@patak-dev patak-dev merged commit d7c04e8 into vitejs:main May 9, 2022
@jprando jprando deleted the patch-1 branch May 17, 2022 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants