javascript - Rollup configuration for filename hashes with a single input and output file - Stack Overflow

Say that I have this basic rollup.config.js file.export default {input: 'srcmain.js',output

Say that I have this basic rollup.config.js file.

export default {
    input: 'src/main.js',
    output: {
        format: 'iife',
        file: 'dist/bundle.js',
    }
};

I want the output file to have its hash in the file name (e.g. bundle-9f02a82b.js). From what I can tell from the docs, the correct way to do this is with options.entryFileNames. However, that setting doesn’t seem to have any effect when outputting to options.file.

I have seen some people online mention that you can use [hash] in output.file, but that doesn’t seem to actually work.

export default {
    input: 'src/main.js',
    output: {
        format: 'iife',
        file: 'dist/bundle-[hash].js', // this doesn’t work
    },
};

Say that I have this basic rollup.config.js file.

export default {
    input: 'src/main.js',
    output: {
        format: 'iife',
        file: 'dist/bundle.js',
    }
};

I want the output file to have its hash in the file name (e.g. bundle-9f02a82b.js). From what I can tell from the docs, the correct way to do this is with options.entryFileNames. However, that setting doesn’t seem to have any effect when outputting to options.file.

I have seen some people online mention that you can use [hash] in output.file, but that doesn’t seem to actually work.

export default {
    input: 'src/main.js',
    output: {
        format: 'iife',
        file: 'dist/bundle-[hash].js', // this doesn’t work
    },
};
Share Improve this question edited Feb 1, 2023 at 16:27 Ryan asked Mar 27, 2021 at 15:25 RyanRyan 1,24213 silver badges24 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

In order to get a hashed file name, you will have to replace output.file with output.dir and output.entryFileNames.

In your example that would be:

export default {
    input: 'src/main.js',
    output: {
        format: 'iife',
        dir: 'build',
        entryFileNames: 'bundle-[hash].js',
    },
};

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744968261a4603815.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信