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

When Built with configure assetFileNames, the assets not found #4503

Closed
7 tasks done
kooriookami opened this issue Aug 4, 2021 · 10 comments
Closed
7 tasks done

When Built with configure assetFileNames, the assets not found #4503

kooriookami opened this issue Aug 4, 2021 · 10 comments

Comments

@kooriookami
Copy link

kooriookami commented Aug 4, 2021

Describe the bug

When project built, run the dist. The page will load all assets in css dictionary, actually the assets aren't in this dictionary.
image

build: {
  outDir: "test_dir",
  assetsDir: "static",
  rollupOptions: {
    output: {
      chunkFileNames: "static/js/[name]-[hash].js",
      assetFileNames(chunkInfo) {
        const fileName = chunkInfo.name;
        let extPath = "[ext]";
        if (/\.(png|jpe?g|gif|svg)$/i.test(fileName)) {
          extPath = "img";
        } else if (/\.(mp4|webm|ogg|mp3|wav|flac|aac)$/i.test(fileName)) {
          extPath = "media";
        } else if (/\.(woff2?|eot|ttf|otf)$/i.test(fileName)) {
          extPath = "fonts";
        }
        return `static/${extPath}/[name]-[hash][extname]`;
      },
    },
  },
},

Reproduction

No response

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
    Memory: 3.63 GB / 15.88 GB
  Binaries:
    Node: 14.17.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1023.0), Chromium (92.0.902.62)
  npmPackages:
    vite: ^2.5.0-beta.0 => 2.5.0-beta.0

Used Package Manager

npm

Logs

no error

Validations

@github-actions
Copy link

github-actions bot commented Aug 5, 2021

Hello @kooriookami. Please provide a minimal reproduction using a GitHub repository or codesandbox. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@kooriookami
Copy link
Author

@sodatea Here it is. https://github.com/kooriookami/vite-assets-error

npm run dev, it's no problem.
image

npm run build
npm run serve, missing the fonts and background image.
image

@dejour
Copy link
Contributor

dejour commented Aug 6, 2021

you need to set base to default value "/" or don't set base. related logic

css = css.replace(assetUrlRE, (_, fileHash, postfix = '') => {

@ygj6
Copy link
Member

ygj6 commented Aug 6, 2021

Of course, you can set other values as well, but ./ is not a correct value in a production environment.

https://vitejs.dev/config/#base:
image

@kooriookami
Copy link
Author

Of course, you can set other values as well, but ./ is not a correct value in a production environment.

https://vitejs.dev/config/#base:
image

Thx, but in some case, I dunno the absolute url, so I have to set a ./. Will this logic be modified later?

@ygj6
Copy link
Member

ygj6 commented Aug 6, 2021

Then you can consider not setting the base, in most cases it is applicable.

@hicc1995
Copy link

I have the same problem

@sapphi-red
Copy link
Member

I was able to reproduce with Vite 2.9.9.
But after upgrading to Vite 3.0.0-alpha.0, it worked. Maybe #7644 (comment) fixed this.
Closing as it is fixed.

@patak-dev
Copy link
Member

#7644 was released in 3.0.0-alpha.1, so it should be another PR. But great this is solved anyway :)

@sapphi-red
Copy link
Member

I was lying 🤦‍♂️. It was 3.0.0-alpha.1. (I was using ^3.0.0-alpha.0 instead of 3.0.0-alpha.0.)

@github-actions github-actions bot locked and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants