gpt4 book ai didi

reactjs - 将 Grommet 与 ReactJS webpack 和 scss import 一起使用

转载 作者:行者123 更新时间:2023-12-03 13:58:21 24 4
gpt4 key购买 nike

我正在尝试在我的 React 项目中使用 grommet,并且正在使用 webpack。我已经添加了 scss 加载器,当我构建我的应用程序时,我收到以下错误:

ERROR in ./~/css-loader!./~/sass-loader!./scss/index.scss
Module build failed:
@import "inuit-defaults/settings.defaults";
^
File to import not found or unreadable: inuit-defaults/settings.defaults
Parent style sheet: /Users/hduser/sample-app/node_modules/grommet/scss/grommet-core/_settings.scss
in /Users/hduser/sample-app/node_modules/grommet/scss/grommet-core/_settings.scss (line 2, column 1)
@ ./scss/index.scss 4:14-116 13:2-17:4 14:20-122

不知道我做错了什么..

这是我的 webpack.config.js

var webpack = require('webpack');
var path = require('path');

module.exports ={
devtool :'cheap-module-eval-source-map',
entry:[
'webpack/hot/only-dev-server',
'./index.jsx'
],
module:{
loaders:[
{
test: /\.jsx?$/,
exclude :/node_modules/,
include: __dirname,
loader:'react-hot'
},
{
test: /\.jsx?$/,
exclude :/node_modules/,
include: __dirname,
loader:'babel',
query:{
"plugins":["transform-decorators-legacy"],
"presets":["es2015","react"]
}
},
{
test :/\.css?$/,
include: __dirname,
loaders :['style','css']
},
{
test: /\.less$/,
loader: "style!css!less"
},
{
test: /\.json$/,
loader: "json"
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
}
]
},
resolve:{
extensions:['','.js','.jsx']
},
output:{
path: __dirname+'/',
publicPath:'/',
filename:'bundle.js'
},
devServer:{
contentBase: './',
hot:true
},
plugins: [
new webpack.HotModuleReplacementPlugin()
,new webpack.NoErrorsPlugin()
]
}

最佳答案

更新如果您使用 npm3+,您可以简单地执行此操作(请参阅 alan's explanation here ):

{
test: /\.scss$/,
loader: 'style!css!sass?outputStyle=expanded&' +
'includePaths[]=' +
(encodeURIComponent(path.resolve('./node_modules')))
},
<小时/>

或者像这样编写 scss 加载器:

{
test: /\.scss$/,
loader: "style!css!sass?OutputStyle=expaned&" +
'includePaths[]=' +
(encodeURIComponent(
path.resolve(process.cwd(), './node_modules')
)) +
'&includePaths[]=' +
(encodeURIComponent(
path.resolve(process.cwd(),
'./node_modules/grommet/node_modules'))
)
}

关于reactjs - 将 Grommet 与 ReactJS webpack 和 scss import 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38338770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com