0

Hello I have a lot of imports to reducex e.g.

import {groupAddTeacher} from "../../../../../../redux/actions/group";
import {groupAddEvent} from "../../../../../../redux/actions/group";

How can I replace a path by excluding ../../../../../../

I using webpack

entry: "./src/index.js",
1
  • 2
    If you Google "webpack absolute import" there's a bunch of articles and tutorials and such on how to get absolute importing working. The actual specific config may vary depending on your webpack version. Commented Mar 7, 2019 at 11:40

2 Answers 2

6

Use webpack's resolve: 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')
  }
}

Then you can do

import { groupAddEvent, groupAddTeacher } from 'actions/group';

Hope this solves your problem!

Sign up to request clarification or add additional context in comments.

Comments

1

You can give a alias in your module exports

alias: {
    src: path.resolve(__dirname + '/root')
}

Then you can do something like:

import { groupAddTeacher }from 'root/redux/actions/group'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.