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