我正在试驾rollupjs https://rollupjs.org/#using-rollup-with-npm将节点应用程序打包成bundle.js
我很困惑。
rollup 是否支持捆绑全节点应用程序(包括node_modules
),或者只是项目中的 js 文件?
我有一个标准节点项目(1index.js https://github.com/datproject/dat/blob/master/index.js, 数千个文件node_modules
)并且只想要一个bundle.js
。我试过:
rollup.config.js:
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
export default {
entry: 'index.js',
dest: 'bundle.js',
format: 'iife',
plugins: [
commonjs({
// non-CommonJS modules will be ignored, but you can also
// specifically include/exclude files
include: 'node_modules/**', // Default: undefined
// if true then uses of `global` won't be dealt with by this plugin
ignoreGlobal: false, // Default: false
// if false then skip sourceMap generation for CommonJS modules
sourceMap: false, // Default: true
}),
nodeResolve({
jsnext: true,
main: false
})
]
};
无论我尝试什么rollup
变成这个index.js
:
module.exports = require('dat-node') // 88 MB node_modules
用这个命令:
rollup index.js --format iife --output dist/bundle.js -c
to this bundle.js
不添加任何东西node_modules
:
(function () {
'use strict';
module.exports = require('dat-node');
}());
我已经尝试过:
- 交换插件顺序
- 所有不同的命令行选项
- 不同的格式
- 不同的配置文件设置
现在我在想,也许我对rollup的理解不正确,它不支持我想要的。非常感谢帮助!