我正在尝试用汇总来构建我的项目。我已经完成了大部分工作(包括角2),但是我无法转换我的一些填充,因为它们中包含了对require()的调用。即使有了rollup-plugin-node-resolve和rollup-plugin-commonjs,它也不会碰require。
那我怎么才能改变它们呢?我可以使用的一个解决方法是浏览填充,然后在汇总过程中包含浏览器序列化的包,但是这需要大量额外的插件,而且不是一个干净的解决方案,特别是因为我认为汇总应该能够理解CommonJS。
下面是Node.js的一些测试代码:
"use strict";
let rollup = require("rollup");
let fs = require("fs");
let resolve = require("rollup-plugin-node-resolve");
let commonjs = require("rollup-plugin-commonjs");
rollup.rollup({
entry: "src/main.js",
plugins: [
resolve({
jsnext: true,
main: true
}),
commonjs({
include: '**', // also tried src/** node_modules/** and a lot of other stuff.
// Leaving this undefined stops rollup from working
}),
]
}).then(function(bundle) {
bundle.write({
format: "iife",
dest: "www/bundle.js"
})
});然后使用一个简单的文件作为src/main.js,它只包含行require("./some-file.js");,而一个包含任何东西的src/some-file.js演示了这个问题。
发布于 2016-10-05 20:10:43
我在拉拉普吉特的好人的帮助下解决了这个问题。
我需要将moduleName添加到bundle.write选项中,如下所示:
bundle.write({
format: "iife",
dest: "www/bundle.js"
moduleName: "someModule"
})https://stackoverflow.com/questions/39869234
复制相似问题