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

rollupOptions.output.assetFileNames does not work #2944

Closed
6 tasks done
AlttiRi opened this issue Apr 11, 2021 · 10 comments · Fixed by #4352
Closed
6 tasks done

rollupOptions.output.assetFileNames does not work #2944

AlttiRi opened this issue Apr 11, 2021 · 10 comments · Fixed by #4352

Comments

@AlttiRi
Copy link

AlttiRi commented Apr 11, 2021

Describe the bug

rollupOptions.output.assetFileNames does not work.

I have the start project with changed config:

export default defineConfig({
  plugins: [vue()],
  build: {
    rollupOptions: {
      output: {
        entryFileNames: `[name].js`,   // works
        chunkFileNames: `[name].js`,   // works
        assetFileNames: `[name].[ext]` // does not work for images
      }
    }
  }
})

The result build structure looks so:
image
As you can see assetFileNames option was ignored for logo.png.

See the related bug: #378 (comment)

Reproduction

yarn create @vitejs/app my-vue-app --template vue
and use the config above.

System Info

Node: 15.9.0
@vitejs/plugin-vue: ^1.2.1 => 1.2.1
vite: ^2.1.5 => 2.1.5

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

@Alexufo
Copy link

Alexufo commented Jul 22, 2021

Confirm. assetFileNames works only with css. Other extensions puts inside asset folder and become with hash in name.
#4354

@patak-dev
Copy link
Member

@Alexufo @AlttiRi it would be good if you could test your projects against Vite with #4352 to confirm that this PR covers your use cases.
https://vitejs.dev/guide/#using-unreleased-commits

@Alexufo
Copy link

Alexufo commented Jul 22, 2021

@patak-js I am newbie to it.
Should I

  1. clone https://github.com/SegaraRai/vite
  2. git checkout fix-issue-2944
  3. use https://vitejs.dev/guide/#using-unreleased-commits?

@patak-dev
Copy link
Member

Yes, but I think it is better to fork the vitejs/vite repo, clone that locally, and run:

git remote add SegaraRai [email protected]:SegaraRai/vite.git
git fetch SegaraRai fix-issue-2944
git switch --track SegaraRai/fix-issue-2944

or if you have https://cli.github.com/ installed, you can run directly

gh pr checkout 4352

You can copy these commands from the PR, there is an Open With button at the right of the title. It is a good idea to have the main repo in case you later want to check other PRs, or be ready to contribute yourself if you find something later.

Note: also a good read https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/configuring-a-remote-for-a-fork

@Alexufo
Copy link

Alexufo commented Jul 23, 2021

@patak-js Yes, it works! All files become with name as set in assetFileNames mask. Fonts css ico.

By the way, is it possible to put fonts to font folder? Fonts become as many files as usual and I prefer to put files to font folder and css and ico in root.

@patak-dev
Copy link
Member

@patak-js Yes, it works! All files become with name as set in assetFileNames mask. Fonts css ico.

Nice! Thanks for testing

By the way, is it possible to put fonts to font folder? Fonts become as many files as usual and I prefer to put files to font folder and css and ico in root.

Maybe you can specify a different folder depending on the ext of the file? You should join chat.vitejs.dev if you aren't there already, probably there are others that may have the same requirement to discuss with.

@Alexufo
Copy link

Alexufo commented Jul 23, 2021

@patak-js
Please check assetsDir

build: {
  assetsDir: './test/',
  cssCodeSplit: false,
  minify: false,
  rollupOptions: {
    output: {
      entryFileNames: "[name].js",
      assetFileNames: '[name][extname]'

    },
  }
}

Now assetsDir is ignored. I suppose it is a not a good. On this config files create in root folder.
assetsDir works on production branch as expected.

@patak-dev
Copy link
Member

AFAICS this is expected @Alexufo, assetsDir should be ignored if you specify a custom assetFileNames

@SegaraRai would you re-check this also?

@SegaraRai
Copy link
Contributor

@patak-js @Alexufo
At least for now, this is an intended behavior.
Since there's no option that corresponds to assetsDir in rollup.js, we have to include assetsDir in assetFileNames (and entryFileNames, etc.).
This can be done by either the user or Vite, but according to this, it appears to be the user's job for now.

@Alexufo
Copy link

Alexufo commented Jul 24, 2021

Ок. It should be a bit info in docs about it I suppose.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants