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

chore(build): keep same hash for the same files #3878

Merged
merged 4 commits into from
May 31, 2024

Conversation

xachary
Copy link

@xachary xachary commented May 27, 2024

General

The same project code is built twice, but the build file names (hash value) obtained are different.
image

The code causing this problem is located in internal\vite-config\src\config\application.ts:

entryFileNames: assets/entry/[name]-[hash].js

// ...
      build: {
        target: 'es2015',
        cssTarget: 'chrome80',
        rollupOptions: {
          output: {
            // 入口文件名(Here!)
            entryFileNames: `assets/entry/[name]-[hash].js`,
            manualChunks: {
              vue: ['vue', 'pinia', 'vue-router'],
              antd: ['ant-design-vue', '@ant-design/icons-vue'],
            },
          },
        },
      }
// ...

I think it should be reverted to:

// ...
      build: {
        target: 'es2015',
        cssTarget: 'chrome80',
        rollupOptions: {
          output: {
            // 入口文件名(Update here!)
            entryFileNames: 'index.js',
            manualChunks: {
              vue: ['vue', 'pinia', 'vue-router'],
              antd: ['ant-design-vue', '@ant-design/icons-vue'],
            },
          },
        },
      }
// ...

Then, test again(dist3 version === dist4 version !== dist5 version):
image

Only the code affected by the change will have its file name changed after it is built.

About the caching issue of the front-end code, I think it is controlled through something like Nginx, for example:

http {
    server {
        listen 80;
        server_name localhost;

        location / {
            root   C:\\projects\\vue-vben-admin\\dist;
            index  index.html index.htm;
            
            # For files without hash suffix, perform "Compare Cache"; for files with hash suffix, perform "Forced Cache".
            # Files without hash suffix include: HTML entry, JS resource entry, logo, some icon.
            set $else 0;
            if ($uri ~ "\/[^\/]+-[\w0-9\-]{8}\.[a-z]+$")
            {
                expires max;
                set $else 1;
            }
            if ($else = 0) {
                expires 0;
            }
        }
    }
}
  • Pull request template structure not broken

Type

ℹ️ What types of changes does your code introduce?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • My code follows the style guidelines of this project
  • Is the code format correct
  • Is the git submission information standard?
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@wangjue666 wangjue666 merged commit a6086f4 into vbenjs:main May 31, 2024
2 checks passed
@vbenjs vbenjs locked and limited conversation to collaborators Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants