Webpack 3 and CommonsChunkPlugin - Exclude a specific entry point from a provider request

I am working on a large business software that is slowly porting to use Webpack on all pages. I want to start using some typescript helper code embedded in a web package in pages that have not yet started using webpack - they include scripts in the old-fashioned way.

Here are the relevant parts of the configuration:

entry: {
    vendor: [
        // All vendor scripts go here
    ],

    // All entry points for 'webpack' pages...

    // A special entry point that I want to inject into non-webpack pages
    es5Compatibility: [
        'Utility/ES5Compatibility.ts'
    ]
},

// ...

output: {
    path: path.join(__dirname, 'Scripts/bundle'),
    filename: '[name].[chunkhash].bundle.js',
    chunkFilename: '[id].chunk.js'
},
plugins: [
    // ...

    new webpack.optimize.CommonsChunkPlugin({
        name: 'vendor',
        minChunks: Infinity
    })

    // This should NOT get injected into non-webpack pages, as all of the
    // vendor dependencies already exist there
    new HtmlWebpackPlugin({
        chunks: ['vendor'],
        template: 'bundleTemplate.ejs',
        inject: false,
        filename: '_VendorBundle.html'
    }),

    // This should get injected into non-webpack pages WITHOUT requiring
    // the above bundle to be included
    new HtmlWebpackPlugin({
        chunks: ['es5Compatibility'],
        template: 'bundleTemplate.ejs',
        inject: false,
        filename: '_ES5CompatibilityBundle.html'
    }),

    // ...
    new webpack.HashedModuleIdsPlugin(),
]

The problem is that when _ES5CompatibilityBundle.htmlincluded in the page without VendorBundle.html, I get the following Javascript error, since Webpack expects the provider package to be included:

Uncaught ReferenceError: webpackJsonp is not defined

, Webpack ES5 "" , -?

+4

Source: https://habr.com/ru/post/1696239/


All Articles