[英]Rollup.js unresolved dependencies
I am trying to incorporate rollup.js into a project.我正在尝试将 rollup.js 合并到一个项目中。 Currently I am getting the warnings provided below in the console (unresolved dependencies) and I am not sure why or how to fix it:
目前,我在控制台中收到下面提供的警告(未解决的依赖项),但我不确定为什么或如何修复它:
'fs' is imported by node_modules\filereader\FileReader.js, but could not be resolved – treating it as an external dependency
'fs' is imported by commonjs-external:fs, but could not be resolved – treating it as an external dependency
preferring built-in module 'punycode' over local alternative at 'C:\Users\Ryan\OneDrive\Projects\Custom Coding\Zapier\Ryan Test\node_modules\punycode\punycode.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
preferring built-in module 'punycode' over local alternative at 'C:\Users\Ryan\OneDrive\Projects\Custom Coding\Zapier\Ryan Test\node_modules\punycode\punycode.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
Here is the test.js script requiring FileReader and https:这是需要 FileReader 和 https 的 test.js 脚本:
var FileReader = require('filereader');
var https = require('https');
Finally the rollup.config.js file which executes creating the bundle:最后是执行创建包的 rollup.config.js 文件:
var rollup = require('rollup');
var commonjs = require('rollup-plugin-commonjs');
var nodeResolve = require('rollup-plugin-node-resolve');
var globals = require('rollup-plugin-node-globals');
var builtins = require('rollup-plugin-node-builtins');
// build bundle
rollup
.rollup({
entry: 'test.js',
plugins: [
nodeResolve(),
commonjs(),
globals(),
builtins()
]
})
.then(bundle => bundle.write({
dest: 'rollupBundle/bundle.js',
format: 'cjs'
}))
.catch(err => console.log(err.stack));
The CLI will generate more informative warnings — if you update your config file to use the standard form, then you can use rollup -c
instead and it will often give you a URL to help diagnose issues. CLI 将生成更多信息性警告——如果您更新配置文件以使用标准格式,那么您可以改用
rollup -c
,它通常会为您提供一个 URL 来帮助诊断问题。
Here's a config file with the necessary changes to squelch those warnings:这是一个配置文件,其中包含必要的更改以消除这些警告:
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import globals from 'rollup-plugin-node-globals';
import builtins from 'rollup-plugin-node-builtins';
export default {
entry: 'test.js',
dest: 'rollupBundle/bundle.js',
format: 'cjs',
external: [ 'fs' ], // tells Rollup 'I know what I'm doing here'
plugins: [
nodeResolve({ preferBuiltins: false }), // or `true`
commonjs(),
globals(),
builtins()
]
};
UPDATE: The "official" Rollup plugins are now under the @rollup namespace on npm, if you install the two versions mentioned above you will get an "npm WARN deprecated" message, so instead install the newer versions instead:更新:“官方”Rollup 插件现在位于 npm 上的 @rollup 命名空间下,如果您安装上面提到的两个版本,您将收到“npm WARN deprecated”消息,因此请改为安装较新的版本:
npm install @rollup/plugin-commonjs --save-dev
npm install @rollup/plugin-node-resolve --save-dev
then use them like this:然后像这样使用它们:
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.