你好,我有很多进口来减少x例如
import {groupAddTeacher} from "../../../../../../redux/actions/group";
import {groupAddEvent} from "../../../../../../redux/actions/group";
如何通过排除../../../../../../
我正在使用webpack
entry: "./src/index.js",
答案 0 :(得分:5)
使用webpack的解析度:https://webpack.js.org/configuration/resolve/
resolve: {
modules: ['src/redux', 'node_modules'],
extensions: ['.jsx', '.js'],
unsafeCache: true,
alias: {
actions: path.resolve(__dirname, 'src', 'redux', 'actions')
}
}
那你就可以做
import { groupAddEvent, groupAddTeacher } from 'actions/group';
希望这可以解决您的问题!
答案 1 :(得分:1)
您可以在模块导出中提供别名
alias: {
src: path.resolve(__dirname + '/root')
}
然后您可以执行以下操作:
import { groupAddTeacher }from 'root/redux/actions/group'