Configuration 未使用汇总定义require
我有以下Configuration 未使用汇总定义require,configuration,commonjs,rollupjs,Configuration,Commonjs,Rollupjs,我有以下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(
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' })
]
}
var hello = require('./hello.js');
console.log(hello);
我有以下input.js
需要shello.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' })
]
}
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
,但该插件有助于模块的导出
将input.js
更改为:
import x from './hello.js';
console.log(x);
有效。更具体地说,问题似乎是CommonJS插件的包括:“hello.js”
——换句话说,它排除了input.js
。该插件确实翻译了所需的以及模块。导出,但仅适用于它所应用的文件;)