Hash 使用汇总对文件名进行哈希处理

Hash 使用汇总对文件名进行哈希处理,hash,rollupjs,Hash,Rollupjs,我对bundler和rollup非常陌生。在为生产构建时,在rollup.config.js中有条件地散列文件名,同时保存index.html以引用新的.css和.js散列版本的最佳方法是什么 我在中看到了这一点,但我想我不知道如何根据dev/prod设置有条件地设置这些选项 output: { sourcemap: true, format: 'iife', name: 'app', file: 'public/build/bun

我对bundler和
rollup
非常陌生。在为生产构建时,在
rollup.config.js
中有条件地散列文件名,同时保存
index.html
以引用新的
.css
.js
散列版本的最佳方法是什么

我在中看到了这一点,但我想我不知道如何根据
dev/prod
设置有条件地设置这些选项

output: {
        sourcemap: true,
        format: 'iife',
        name: 'app',
        file: 'public/build/bundle.js'
       // entryFileNames : 'bundle[hash].js
    },
或者使用
rollup plugin hash
是更好的解决方案? 仍然不确定更新
index.html
(清单文件选项提供了什么?

您可以使用类似的插件生成一个html文件,该文件引用散列文件名

由于汇总配置文件只是Javascript,因此可以根据dev/prod设置包含一些

const isProduction = process.env.NODE_ENV === 'production';

export default {
  output: {
    sourcemap: true,
    format: 'iife',
    name: 'app',
    file: isProduction ? 'bundle[hash].js' : 'public/build/bundle.js',
  }
};