简体   繁体   中英

Parcel build command not working

I am following the basic tutorial for Parcel to bundle js, css and image files.

My file structure

  dist
  node_modules
  src
    - index.html
    - style.css
    - index.js
    - somemodule.js

When I run parcel ./src/index.html a server is started and the website is displayed correctly. According to the tutorial you can finalize the build using parcel build index.js . I expected to get this output:

  dist
    - style.css
    - index.js
    - index.html

But instead, after running parcel build index.js I get this output:

  dist
    - 4wyd98y98790.css
    - 948y59hslas8.js

What could possibly be going wrong?

The Parcel Bundler output directory is dist by default, but you can specify an output directory by setting option ( -d ).

eg parcel build src/index.html -d build --public-url . You will get the final static files in the build directory.

The tutorial may say parcel build index.js , but you should run parcel build ./src/index.html . The entry point of your app is index.html.

Since some commands seem to change over time, I'm going to share here the set up that worked for me up to date.

 "scripts": {
    "start": "parcel src/index.html -p 3000 --open",
    "build:parcel": "parcel build ./src/index.html --public-url ./ --no-source-maps",
    "build": "npm run clean && npm run build:parcel",
    "clean": "rm -rf dist/*"
  }

And I run the script using npm run-script build

My tree project was:

project
    |dist
      |OUTPUT FILES
    |src
      |OTHER INPUT FOLDERS
      |index.html
    package.json

尝试删除旧的构建内容,例如dist文件夹并再次构建

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM