【问题标题】:How to use background-images with SCSS + Parcel.js如何在 SCSS + Parcel.js 中使用背景图像
【发布时间】:2019-07-20 09:30:00
【问题描述】:

我正在尝试使用 parcel.js 和 SCSS 来使用背景图像,但得到:

Uncaught SyntaxError: Unexpected token

或者有时得到:

无法读取 null 的属性“js”

这是我的 scss:

.hero{
  background-image: url('../../images/2ndpaper.jpg');
}

这是我的 js:

import "../styles/index.scss";
import paperbg from "../images/2ndpaper.jpg";

这是我的 package.json:

 {
  "name": "development",
  "version": "1.0.0",
  "description": "CB PC - Web Development",
  "main": "index.js",
  "scripts": {
    "dev": "parcel src/index.html",
    "build": "parcel build src/index.html --out-dir prod"
  },
  "keywords": [
    "client",
    "website"
  ],
  "author": "Designs by Harp",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-class-properties": "^7.3.0",
    "parcel-bundler": "^1.11.0"
  },
  "dependencies": {
    "bootstrap-4-grid": "^2.4.1",
    "gsap": "^2.0.2",
    "jshint": "^2.10.1",
    "sass": "^1.17.2"
  }
}

可能出了什么问题?

【问题讨论】:

  • 你解决了吗?

标签: javascript sass parceljs


【解决方案1】:

我会添加新的 npm 脚本,尝试按照 Parcel documentation 中的建议添加“--public-url ./”

"build2": "parcel build src/index.html --public-url prod"

【讨论】:

    猜你喜欢
    • 2014-02-03
    • 1970-01-01
    • 2016-09-20
    • 2022-07-11
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    相关资源
    最近更新 更多