rollup报错:
Error: You must set either “output.file” for a single-file build or “output.dir” when generating multiple chunks
这个错误是output
的file
和dir
配置问题,先看看下面三种配置就明白了。
第一种
代码:
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
export default {
input: 'src/main.js',
output: {
file: 'bundle.js',
format: 'iife',
},
plugins: [
resolve(),
babel({ babelHelpers: 'bundled' })
]
};
打包目录文件:bundle.js
第二种
代码:
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
export default {
input: 'src/main.js',
output: {
format: 'iife',
dir:'build'
},
plugins: [
resolve(),
babel({ babelHelpers: 'bundled' })
]
};
打包目录文件:build/main.js
第三种
代码:
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
export default {
input: 'src/main.js',
output: {
file: 'build/bundle.js',
format: 'iife',
},
plugins: [
resolve(),
babel({ babelHelpers: 'bundled' })
]
};
打包目录文件:build/bundle.js