简体   繁体   English

包裹构建命令不起作用

[英]Parcel build command not working

I am following the basic tutorial for Parcel to bundle js, css and image files.我正在遵循Parcel的基本教程来捆绑 js、css 和图像文件。

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.当我运行parcel ./src/index.html ,服务器启动并且网站显示正确。 According to the tutorial you can finalize the build using parcel build index.js .根据教程,您可以使用parcel build index.js完成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:但是,在运行parcel build index.js我得到了这个输出:

  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 ). Parcel Bundler 输出目录默认为dist ,但您可以通过设置选项 ( -d ) 指定输出目录。

eg parcel build src/index.html -d build --public-url .例如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 .教程可能会说parcel build index.js ,但你应该运行parcel build ./src/index.html The entry point of your app is index.html.您的应用程序的入口点是 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我使用npm run-script build

My tree project was:我的树项目是:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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