gpt4 book ai didi

css - Laravel scss npm run dev - 无法解析 '../images/bg-main.png'

转载 作者:行者123 更新时间:2023-12-05 02:57:55 25 4
gpt4 key购买 nike

我有 Laravel 元素,我想从 scss 生成 css 文件。我的 webpack.mix.js 文件如下所示:

mix.sass('resources/assets/sass/style.scss', 'public/css/style.css');

当我运行命令 npm run dev 时出现错误:

ERROR in ./resources/assets/sass/style.scss
Module build failed: ModuleNotFoundError: Module not found: Error: Can't resolve '../images/bg-main.png' in '/var/www/html/bitpay/resources/assets/sass'

ERROR in ./node_modules/css-loader??ref--4-2!./node_modules/postcss-loader/lib??postcss!./node_modules/resolve-url-loader??ref--4-4!./node_modules/sass-loader/lib/loader.js??ref--4-5!./resources/assets/sass/style.scss
Module not found: Error: Can't resolve '../images/bg-main.png' in '/var/www/html/bitpay/resources/assets/sass'
@ ./node_modules/css-loader??ref--4-2!./node_modules/postcss-loader/lib??postcss!./node_modules/resolve-url-loader??ref--4-4!./node_modules/sass-loader/lib/loader.js??ref--4-5!./resources/assets/sass/style.scss 7:14663-14695
@ ./resources/assets/sass/style.scss
@ multi ./node_modules/laravel-mix/src/builder/mock-entry.js ./resources/assets/sass/style.scss

ERROR in ./node_modules/css-loader??ref--4-2!./node_modules/postcss-loader/lib??postcss!./node_modules/resolve-url-loader??ref--4-4!./node_modules/sass-loader/lib/loader.js??ref--4-5!./resources/assets/sass/style.scss
Module not found: Error: Can't resolve '../images/bg-recommendations.png' in '/var/www/html/bitpay/resources/assets/sass'
@ ./node_modules/css-loader??ref--4-2!./node_modules/postcss-loader/lib??postcss!./node_modules/resolve-url-loader??ref--4-4!./node_modules/sass-loader/lib/loader.js??ref--4-5!./resources/assets/sass/style.scss 7:17599-17642 7:22181-22224
@ ./resources/assets/sass/style.scss
@ multi ./node_modules/laravel-mix/src/builder/mock-entry.js ./resources/assets/sass/style.scss

如何将图片文件夹添加到编译中?

最佳答案

问题是 mix 找不到您在 style.scss 中引用的图像 bg-main.png

您可以添加不处理 css url 的混合选项,如下所示:

mix.options({
processCssUrls: false
});

这会产生一些后果:

  • mix 不会检查图像是否存在。
  • mix不会自动复制图片到public目录。

更好的解决方案是将图像放在 mix 期望的位置:mix 期望 ../images/bg-main.png 位于目录 resources/images/

引用资料:

关于css - Laravel scss npm run dev - 无法解析 '../images/bg-main.png',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59516514/

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