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

How add [hash] for .js .css and other files in build? #4368

Closed
popuguytheparrot opened this issue May 14, 2018 · 6 comments · Fixed by #14279
Closed

How add [hash] for .js .css and other files in build? #4368

popuguytheparrot opened this issue May 14, 2018 · 6 comments · Fixed by #14279

Comments

@popuguytheparrot
Copy link
Contributor

I want add [name][hash].[ext] for .js .css and other files in build

For example in webpack i have file-loader and i have

options: {
              name: '[name]__[hash]__.[ext]',
              publicPath: '...',
              outputPath: '...',
            },

How do same in next.config.js? Or nextjs do hashing files when build?

Tech Version
next 5.1.0
node 10.0.0
@popuguytheparrot
Copy link
Contributor Author

it working but look like as shi~

const nextConfiguration = {
  webpack: (config, { dev, buildId }) => {
    if (!dev) {
      const nextExtractTextPlugin = config.plugins.find(
        element => element.__proto__.constructor.name === 'ExtractTextPlugin'
      );
      nextExtractTextPlugin.filename = `static/style.${buildId}.css`;
      config.plugins.push(nextDefinePlugin(buildId), nextCleanWebpackPlugin);
      return config;
    }
    config.plugins.push(nextDefinePlugin);
    return config;
  }
};

@timneutkens
Copy link
Member

Doesn't seem like a Next.js issue. Maybe you're using one of the next-plugins, in that case file it there. Also, when creating issues, please follow the issue template.

@popuguytheparrot
Copy link
Contributor Author

@timneutkens what about extractCSSPlugin in context webpack: (config, context) => {
how i can manipulate it

@popuguytheparrot
Copy link
Contributor Author

@timneutkens nextjs do hashing files when build?

@popuguytheparrot
Copy link
Contributor Author

@timneutkens do u answer me?

@ghengeveld
Copy link

ghengeveld commented May 15, 2018

@Popugune The issue tracker is to report bugs in Next.js, not to ask for support. You can try asking your question on Spectrum.

It looks like you're on the right track with your nextConfiguration above.

@lock lock bot locked as resolved and limited conversation to collaborators May 15, 2019
kodiakhq bot pushed a commit that referenced this issue Jun 20, 2020
Updates the way filenames are generated for browser compilation.
Notably:
- All entry bundles now have hashes in production, this includes pages (previously pages used a buildId in the path)
- The AmpFiles no longer depends on hardcoded bundle names, it uses the buildManifest instead (internals)
- All cases where we match the page name from the chunk/entrypoint name now use the same function `getRouteFromEntrypoint` (internals)
- In development we no longer include the "faked" `buildId` set to `development` for page files, instead we just use the `/_next/static/pages` path (was `/_next/static/development/pages`). This was changed as it caused unneeded complexity and makes generating the bundles easier (internals)
- Updated tons of tests to be more resilient to these changes by relying on the buildManifest instead of hardcoded paths (internals)

Follow up of these PRs:
#13759
#13870
#13937
#14130
#14176
#14268


Fixes #6303
Fixes #12087 
Fixes #1948
Fixes #4368
Fixes #4255
Fixes #2548
rokinsky pushed a commit to rokinsky/next.js that referenced this issue Jul 11, 2020
Updates the way filenames are generated for browser compilation.
Notably:
- All entry bundles now have hashes in production, this includes pages (previously pages used a buildId in the path)
- The AmpFiles no longer depends on hardcoded bundle names, it uses the buildManifest instead (internals)
- All cases where we match the page name from the chunk/entrypoint name now use the same function `getRouteFromEntrypoint` (internals)
- In development we no longer include the "faked" `buildId` set to `development` for page files, instead we just use the `/_next/static/pages` path (was `/_next/static/development/pages`). This was changed as it caused unneeded complexity and makes generating the bundles easier (internals)
- Updated tons of tests to be more resilient to these changes by relying on the buildManifest instead of hardcoded paths (internals)

Follow up of these PRs:
vercel#13759
vercel#13870
vercel#13937
vercel#14130
vercel#14176
vercel#14268


Fixes vercel#6303
Fixes vercel#12087 
Fixes vercel#1948
Fixes vercel#4368
Fixes vercel#4255
Fixes vercel#2548
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 a pull request may close this issue.

3 participants