我是reactjs的新手,我已经读过article了,但我不知道怎么读。我正在尝试在导入时创建别名。这是有效的
import BootstrapCss from '../../../dist/static/bootstrap/css/bootstrap.css';
但这么做可不是什么好事
import BootstrapCss from 'bootstrap';
在我的webpack.config.js中,我有这个
... resolve: { extensions: ['', '.js', '.jsx', 'css', '.scss', '.eot', '.ttf', '.svg', '.woff'], modulesDirectories: ['node_modules', 'scripts', 'images', 'fonts', 'dist'], alias: { bootstrap : path.resolve(__dirname, '/dist/static/bootstrap/css/bootstrap.css') } } ...和我不知道如何更改我收到错误的node_modules路径的路径
Module not found: Error: Cannot resolve module 'bootstrap' in E:\path-to-folder\src\components\home resolve module bootstrap in E:\path-to-folder\src\components\home looking for modules in E:\path-to-folder\node_modules E:\path-to-folder\node_modules\bootstrap doesn't exist (module as directory) resolve 'file' bootstrap in E:\path-to-folder\node_modules
发布于 2016-12-08 23:32:49
您可能想要查看这个Babel插件:https://www.npmjs.com/package/babel-plugin-webpack-alias,它应该允许您在前端代码中使用这些别名。(假设您有一个有效的Babel配置)
除此之外,在别名前添加一个~似乎可以解决这个问题。(参考:https://github.com/kriasoft/react-starter-kit/issues/945)
https://stackoverflow.com/questions/41039856
复制相似问题