我正在从 Webpack 迁移到 Parcel,并在我的组件中使用这样的文件夹别名:
import * as authActions from 'actions/authActions';
我收到此错误:Cannot find module 'actions/authActions'
奇怪的是,它只在使用时显示build
,它在开发模式下工作,而不是在生产模式下。
我已经在 package.json 中设置了我的别名,就像文档说的那样:
{
"scripts: {
"build-client": "parcel build client/index.html dist/client",
"build-server": "parcel build server/index.js --target node -d dist/server",
"build-test": "yarn build-server && node ./dist/server/index.js"
},
"alias": {
"actions": "./client/actions"
}
}
这是一个服务器端渲染的应用程序,我在不同的地方导入组件,我不能使用默认的 Parcel 根,因为它是相对于入口文件的。
我怎样才能让它正确解析别名?