简体   繁体   English

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

[英]Use chunkhash only for some output files in webpack

I am building an application that is being loaded as a plugin in other applications. 我正在构建一个正在作为其他应用程序中的插件加载的应用程序。 Think grammarly or intercom. 语法思考或对讲。
So, I will have a javascript file (the loader) that customers need to reference in their application. 因此,我将有一个javascript文件(加载程序),客户需要在其应用程序中引用该文件。
This file in turn adds an iFrame and loads my index.html which references my main bundle. 该文件又添加了一个iFrame并加载了引用我的主捆绑包的index.html。

Now, I want to have the loader to not have a chunkhash in its filename but the bundle should have the chunkhash. 现在,我希望加载程序的文件名中不包含chunkhash,但捆绑软件中应包含chunkhash。

Possible? 可能? If so, how? 如果是这样,怎么办?

My webpack config (ejected from create-react-app-typescript ): 我的webpack配置(从create-react-app-typescript 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, '/'),
},

Why not use a function for filename . 为什么不对filename使用函数。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM