当我在脚本中使用带有模块的 typescript 装饰器时,rollupjs 会捆绑整个模块而不是导入的模块。
main.js
import { outter } from './index.js';
let a = new outter();
index.js
export * from './display';
export * from './form';
显示.js
export var outter = (function (_super) {
console.log();
})();
表单.js
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
export var err;
(function (err) {
err[err["name"] = 0] = "name";
err[err["error"] = 1] = "error";
})(err || (err = {}));
export var formV = (function (_super) {
__extends(formV, _super);
function formV(element, options) {
_super.call(this, options, element);
}
__decorate([
Property(err.name)
], formV.prototype, "err", void 0);
return formV;
}());
formV 模块并未导入 main.js 文件中,但它也与输出文件捆绑在一起。
rollup.config.js
import nodeResolve from 'rollup-plugin-node-resolve';
export default {
entry: 'main.js',
plugins: [
nodeResolve({ jsnext: true })
],
targets: [
{ dest: 'dist/rollup.js', format: 'cjs' },
{ dest: 'dist/rollup.es.js', format: 'es' },
{ dest: 'dist/rollup.amd.js', format: 'amd' }
],
treeshake: true
};