Rollup.js-从包中排除模块

问题描述 投票:0回答:1

我遇到的问题是我无法正确配置rollup.config.js的配置。我想从捆绑中排除libModule.js模块。到目前为止,我已经尝试了许多配置和设置,但均未成功。有人可以帮我吗。

这里是我的文件夹结构。

my-folder
└────src
│    └───index.ts
│    └───libModule.js
│
└────dist
│    └───bundle.js
│
└───rollup.config.js

index.ts

import $ from './libModule';

container.appendChild(
  $.element('img', { id: 'image', src: '9592/test_1.png', style: '' })
);

libModule.js

export default function $(e) {
  return document.getElementById(e)
}
...

rollup.config.js

import path from 'path';
import typescript from 'rollup-plugin-typescript2';
const externalId = path.resolve(__dirname, './src/libModule.js');

export default {
  input: './src/index.ts',
  output: {
    file: './dist/bundle.js',
    format: 'iife',
    name: 'sco',
    sourcemap: true,
    interop: false,
    globals: {
      [externalId]: '$'
    }
  },
  external: [externalId],
  plugins: [
    typescript({
      typescript: require('typescript'),
    })
  ],
}

tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist",
    "module": "es6",
    "noImplicitAny": true,
    "sourceMap": true,
    "target": "es5",
    "allowJs": true,
    "moduleResolution": "node"
  },
  "include": [
    "src/**/*"
  ],
  "exclude": ["node_modules"],
  "typedocOptions": {
    "inputFiles": [".src/**/*"],
    "mode": "modules",
    "out": "docs",
    "readme": "none"
  }
}
config es6-modules rollupjs
1个回答
0
投票

问题是您需要将正确的标识符标记为外部。

https://github.com/pvissenberg/typescript_workspace/pull/1

© www.soinside.com 2019 - 2024. All rights reserved.