我正在尝试使用webpack创建一个包.我有一点复杂的依赖:一些组件需要位于某个/home/.../
文件夹中的其他组件.
组件(/home/.../far-away-components/base-component.js
文件):
import {base_component} from "base-component"; exports class MyComponent extends base_component { ... }
webpack.config.js
:
var path = require("path"); module.exports = { ... module: { loaders: [ { test: /\.(js)$/, loader: "babel", query: { presets: ['react', 'es2015', "stage-0"] } } ] }, resolve: { alias: { "base-component": "/home/.../far-away-components/base-component.js" } };
问题是该far-away-components
文件夹不包含node_modules
,我收到一个错误:Couldn't find preset "react" relative to directory "/home/.../far-away-components"
.
如何设置resolve
为babel-loader
预设?
来自github问题的解决方案:
query: { presets: [ 'babel-preset-es2015', 'babel-preset-react', 'babel-preset-stage-0', ].map(require.resolve), }