Skip to content

Instantly share code, notes, and snippets.

@davidgilbertson
Last active November 10, 2022 03:45
Show Gist options
  • Save davidgilbertson/838312f0a948423e4c4da30e29600b16 to your computer and use it in GitHub Desktop.
Save davidgilbertson/838312f0a948423e4c4da30e29600b16 to your computer and use it in GitHub Desktop.

Revisions

  1. davidgilbertson revised this gist Sep 8, 2018. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions webpack.config.js
    Original file line number Diff line number Diff line change
    @@ -20,10 +20,12 @@ module.exports = {
    vendor: {
    test: /[\\/]node_modules[\\/]/,
    name(module) {
    // get the name (e.g. node_modules/this-part/not/this/part)
    const packageName = module.resource.match(/[\\/]node_modules[\\/](.*?)[\\/]/)[1];
    // get the name. E.g. node_modules/packageName/not/this/part.js
    // or node_modules/packageName
    const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];

    return `npm.${packageName}`;
    // npm package names are URL-safe, but some servers don't like @ symbols
    return `npm.${packageName.replace('@', '')}`;
    },
    },
    },
  2. davidgilbertson created this gist Sep 5, 2018.
    32 changes: 32 additions & 0 deletions webpack.config.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    const path = require('path');
    const webpack = require('webpack');

    module.exports = {
    entry: path.resolve(__dirname, 'src/index.js'),
    plugins: [
    new webpack.HashedModuleIdsPlugin(), // so that file hashes don't change unexpectedly
    ],
    output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].[contenthash].js',
    },
    optimization: {
    runtimeChunk: 'single',
    splitChunks: {
    chunks: 'all',
    maxInitialRequests: Infinity,
    minSize: 0,
    cacheGroups: {
    vendor: {
    test: /[\\/]node_modules[\\/]/,
    name(module) {
    // get the name (e.g. node_modules/this-part/not/this/part)
    const packageName = module.resource.match(/[\\/]node_modules[\\/](.*?)[\\/]/)[1];

    return `npm.${packageName}`;
    },
    },
    },
    },
    },
    };