【发布时间】:2018-07-27 01:05:48
【问题描述】:
我正在使用rollup 构建我的库,并且我依赖于lodash。
但是当我运行rollup 来捆绑我的代码时,我收到了这个警告。
(!) Unused external imports
reduce imported from external module 'lodash' but never used
我的代码示例如下:
import { reduce } from "lodash"
export function someutilityfunction(args) {
return reduce(args,() => {
// do somthing
}, {}) // A generic use case of reduce function
}
捆绑的 库工作正常。
我什至尝试过使用
import * as _ from "lodash"
和lodash-es 而不是lodash
但没有成功。
这是我的 rollup.config.js
import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import filesize from 'rollup-plugin-filesize'
import typescript from 'rollup-plugin-typescript2'
import commonjs from 'rollup-plugin-commonjs'
import uglify from 'rollup-plugin-uglify'
let production = (process.env.NODE_ENV == "production")
export default {
input: 'src/index.ts',
output: {
file: 'lib/index.js',
format: 'cjs',
name: 'my-library',
sourcemap: true
},
external: [
'rxjs',
'axios',
'lodash'
],
plugins: [
resolve(),
typescript({
tsconfigOverride: {
compilerOptions: {
declaration: true,
moduleResolution: "node",
allowSyntheticDefaultImports: true
}
},
// verbosity: 3,
clean: true,
rollupCommonJSResolveHack: true,
abortOnError: false,
typescript: require('typescript'),
}),
commonjs(),
babel({
exclude: 'node_modules/**'
}),
production && uglify(),
filesize()
],
watch: {
include: 'src/**'
}
};
我以前使用过这个 rollup config,它一直运行良好,直到现在。
我错过了什么吗?
而且我知道问题的标题可以更笼统。随时改进帖子。
【问题讨论】:
标签: javascript import lodash node-modules rollupjs