vuejs / vue-loader

📦 Webpack loader for Vue.js components
MIT License
4.99k stars 914 forks source link

Build is unstable when project is build in a different path #2028

Closed mvorisek closed 1 year ago

mvorisek commented 1 year ago

https://github.com/atk4/ui/blob/dedb4cea3191e45ba2334ad48c0f98c6d25edf32/.github/workflows/test-unit.yml#L344 hack is needed to make babel build stable, otherwise a variable name in the resulting build is containing the resolved local path, making the build unstable

how to reproduce:

  1. checkout https://github.com/atk4/ui
  2. cd into js/ dir
  3. run npm install (without the patch from above applied) and npm run build
  4. notice the git changes in ../public/js dir containing a local path
mvorisek commented 1 year ago

@alexander-akait do you have an idea how to fix it or is a webpack issue instead?

alexander-akait commented 1 year ago

Oh, missed your issue (not sure how it happens), give me time to look

alexander-akait commented 1 year ago

@mvorisek

There is a small bug - https://github.com/vuejs/vue-loader/blob/main/src/index.ts#L285, it should be:

code += `\n\nimport exportComponent from ${stringifyRequest(exportHelperPath)}`;

and https://github.com/vuejs/vue-loader/blob/main/src/index.ts#LL47C1-L47C75, should be:

const exportHelperPath = require.resolve('./exportHelper');

stringifyRequest makes a request relative to context, so you will not have absolute paths and a code generation in the development mode will be more stable, you can send a PR with fix

alexander-akait commented 1 year ago

This happened because you have node_modules inside js directory, but your source code in src and they are on the same level (i.e. js and src directories)