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...
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
}
}
Добрый день. А чем этот плагин отличается от встроенной опции в вебпаке resolve.alias?
Может быть, я посмотрю
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"
}
...