仅对Webpack中的某些输出文件使用chunkhash

时间:2018-12-06 10:48:53

标签: javascript typescript webpack

我正在构建一个作为插件加载到其他应用程序中的应用程序。语法思考或对讲。
因此,我将有一个javascript文件(加载程序),客户需要在其应用程序中引用该文件。
该文件又添加了一个iFrame并加载了引用我的主捆绑包的index.html。

现在,我希望加载程序的文件名中不包含chunkhash,但捆绑软件中应包含chunkhash。

可能吗?如果可以,怎么办?

我的webpack配置(从create-react-app-typescript弹出):

entry: {
    app: [require.resolve('./polyfills'), paths.appIndexJs],
    loader: "./src/integration/loader.ts"
},
output: {
    // The build folder.
    path: paths.appBuild,
    // Generated JS file names (with nested folders).
    // There will be one main bundle, and one file per asynchronous chunk.
    // We don't currently advertise code splitting but Webpack supports it.
    filename: '[name].[chunkhash:8].js',
    chunkFilename: '[name].[chunkhash:8].chunk.js',
    // We inferred the "public path" (such as / or /my-project) from homepage.
    publicPath: publicPath,
    // Point sourcemap entries to original disk location (format as URL on Windows)
    devtoolModuleFilenameTemplate: info =>
        path
            .relative(paths.appSrc, info.absoluteResourcePath)
            .replace(/\\/g, '/'),
},

1 个答案:

答案 0 :(得分:4)

为什么不对filename使用函数。

...
output: {
    ...
    filename: (chunkData) => {
        return chunkData.chunk.name === 'loader'
            ? '[name].js'
            : '[name].[chunkhash:8].js';
    },
}

请参见https://webpack.js.org/configuration/output/#output-filename

相关问题