Skip to content

how to config webpack to package vendor to random file name? #1248

Closed

Description

@naivefun

Now I see the file name remains unchanged if only main script has been edited.
However I see cloudflare/browser cache is causing issues, I do not know why. Maybe file remains the same but content is different?

I'm thinking to change to random file name anyway so that no cache will be used.

Activity

  1. karolmie1 commented on Dec 9, 2016

    @karolmie1
    Contributor

    As far as I remember in production build vendor name is appended file hash, so that should help in that case. Dev builds should not be run on productions, as they lack the glory of tree shaking and uglification.

    This behavior is produced by WebpackMd5Hash plugin.

  2. joshwiens commented on Dec 9, 2016

    @joshwiens
    Contributor

    @naivefun - There are quite a few ways to implement cache busting. I personally roll with something like this but I also have a moderately complex caching setup between my app, docker containers & nginx.

      entry: {
          'polyfills':   './src/polyfills.browser.ts',
          'vendor':    './src/vendor.browser.ts',
          'main':        './src/main.browser.ts'
      },
      output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name].[chunkhash].js',
        chunkFilename: '[name].[chunkhash].js'
      },
      plugins: [
        new webpack.optimize.CommonsChunkPlugin({
          name: "vendor",
          minChunks: Infinity,
        }),
        new WebpackMd5Hash(),
        new ManifestPlugin(),
        new ChunkManifestPlugin({
          filename: "chunk-manifest.json",
          manifestVariable: "webpackManifest"
        })
      ]
    

    Point being, this is one of those things that is really dependent on exactly what you are trying to achieve and how you are setup. Any way it goes, you will need WebpackMd5Hash as @karolmie1 mentioned.

    It's also worth noting that what I run in production isn't based off the starter, so just grabbing that snippet isn't going to work ( just an example ).

    I highly suggest reading https://webpack.js.org/guides/caching/ more than once and then start hacking on your project. Caching is one of those things you can get "kind of right" and end up with weird results.

    You are going to want to understand your own caching implementation completely as it pertains to your app & the deployment stack it is running on. Docs + Trial and error is the best way to get there imo.

  3. karolmie1 commented on Jul 28, 2017

    @karolmie1
    Contributor

    @naivefun Can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions