gpt4 book ai didi

configuration - require 没有使用 rollup 定义

转载 作者:行者123 更新时间:2023-12-04 13:02:39 25 4
gpt4 key购买 nike

我有以下 rollup.config.js :

import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';

export default {
input: 'input.js',
output: {
file: 'output.js',
format: 'iife'
},
plugins: [
nodeResolve(
{
jsnext: true,
main: true
}
),
commonjs({ include: 'hello.js' })
]
}

我有以下 input.js其中 require s hello.js :
var hello = require('./hello.js');

console.log(hello);

hello.js很简单:
module.exports = 'hello';

我要 output.js不包括 require语法并将其替换为字符串 'hello' .

相反,我仍然看到这一行 var hello = require('./hello.js');
如何用汇总插件替换这一行? (我认为这就是 commonjs 插件的用途)。

在此先感谢您的帮助!

最佳答案

解决了。

问题出在我的 input.js文件。

插件不支持 require ,但该插件有助于 module.exports .

input.js成为:

import x from './hello.js';

console.log(x);

工作。

关于configuration - require 没有使用 rollup 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51922005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com