【发布时间】:2018-01-24 06:02:14
【问题描述】:
我正在试驾rollupjs 将一个节点应用程序打包到bundle.js 中,我很困惑。
rollup 是否支持捆绑一个完整的节点应用程序(包括
node_modules),还是只支持您项目中的 js 文件?
我有一个标准节点项目(1 个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
到这个bundle.js 而不添加来自node_modules 的任何内容:
(function () {
'use strict';
module.exports = require('dat-node');
}());
我已经试过了:
- 交换插件序列
- 所有不同的命令行选项
- 不同的格式
- 不同的配置文件设置
现在我在想,也许我对汇总的理解不正确,它不支持我想要的。非常感谢您的帮助!
【问题讨论】:
标签: javascript node.js npm bundling-and-minification rollupjs