如何在Scss + Parcel.js中使用背景图像

时间:2019-02-26 18:52:48

标签: javascript web sass parceljs

我正在尝试使用parcel.js和scss使用背景图像,但出现 未捕获的SyntaxError:意外令牌<7d6454d814b6ce2e1592d3937c337ef3.js:1 错误

或者有时会得到:无法读取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"
  }
}

可能是什么问题?谢谢。

1 个答案:

答案 0 :(得分:0)

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

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