React 24: babel-plugin-module-resolver

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024
  • Наш главный курс "JavaScript старт" - constcode.ru/j...
    Бесплатная консультация - constcode.ru/f...
    Контакты:
    Сайт - constcode.ru
    VK - constcode
    RUclips - / @web-constcode6252
    Telegram - t.me/constcode
    Discord - / discord
    Материал урока:
    www.npmjs.com/...
    create-react-a...
    github.com/atl...

Комментарии • 4

  • @strel9
    @strel9 2 года назад +2

    Usage with create-react-app
    create-react-app by default don't use .babelrc, so in webpack.config.dev.js, add plugins property within js loader like below. Note that plugins recieve an array.
    // Process JS with Babel.
    {
    test: /\.(js|jsx|mjs)$/,
    include: paths.appSrc,
    loader: require.resolve('babel-loader'),
    options: {
    plugins: [
    ["module-resolver", {
    "root": ["./src/App"],
    "alias": {
    "test": "./test",
    }
    }]
    ],
    cacheDirectory: true
    }
    }

  • @МаксимЛибер-ф2н
    @МаксимЛибер-ф2н 3 года назад +2

    Добрый день. А чем этот плагин отличается от встроенной опции в вебпаке resolve.alias?

  • @layerok315
    @layerok315 Год назад

    you can also use regex as an alias, this way you don't need to list all your folders. Like so
    package.json
    ...
    "alias": {
    "^@(.+)": "./src/\\1"
    }
    ...