使用以下配置构建TypeScript项目(所有节点模块都是最新的)时,我收到一条错误消息,名为**“Error:构建多个区块时,必须使用output.dir选项,而不是output.file。"**
有人能帮忙吗?谢谢。
// [EDIT: I've simplified this configuration as the original
// one caused some misunderstandings]
// rollup.config.js
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import typescript from 'rollup-plugin-typescript2'
import { uglify } from 'rollup-plugin-uglify'
import gzip from 'rollup-plugin-gzip'
export default {
input: 'src/main/my-project.ts',
output: {
file: 'dist/my-project.umd.production.js',
format: 'umd',
name: 'MyProject',
sourcemap: false,
globals: {
'react': 'React'
}
},
external: ['react'],
plugins: [
resolve(),
commonjs(),
typescript({
exclude: 'node_modules/**'
}),
uglify(),
gzip()
]
}
这是我的tsconfig.json,可能很重要。构建脚本由rollup --c rollup.config.js
启动:
{
"compilerOptions": {
"target": "ES5",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"downlevelIteration": true,
"sourceMap": true,
"lib": ["es5", "es6", "dom"],
"esModuleInterop": true,
"baseUrl": ".",
"typeRoots": [
"node_modules/@types"
],
"types": [
"node", "react", "react-dom", "mocha", "chai"
]
},
"files": [
"src/main/my-project.ts"
],
"include": [
"./src/**/*.ts*"
]
}
3条答案
按热度按时间2o7dmzc51#
我也遇到过类似的问题,作为修复,我需要在package.json中指定输出模块
它与汇总配置保持一致:
mmvthczy2#
对于那些仍在努力解决这个问题的人,并且您在组件中使用动态导入,那么您应该在
output object
之上添加inlineDynamicImports: true
pcww981p3#
看起来配置不是问题所在,但是我的节点模块的版本仍然有问题。
在我完成以下操作后,一切都恢复正常: