简体   繁体   English

如何使用 css 样式表“npm start”一个 html 文件?

[英]How to "npm start" an html file with css stylesheet?

I'm new to coding and (obviously) getting Qs in stack overflow allows me to interact more with other developers.我是编码新手,并且(显然)在堆栈溢出中获取 Q 允许我与其他开发人员进行更多交互。

I code on VS Code and I know there is a "live server" extension in order to do exactly what I need my code to do.我在 VS Code 上编码,并且我知道有一个“实时服务器”扩展,以便完全执行我需要我的代码执行的操作。 BUT, up until the last time I tried "npm start" for another code it was working and now I'm starting a simple html/css/js code it just says:但是,直到我最后一次尝试“npm start”来获取另一个正在运行的代码,现在我开始了一个简单的 html/css/js 代码,它只是说:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\.\..\...\....\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\.\..\...\....\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

I've done a bit of research and I know i need to either run npm install or npm init .我做了一些研究,我知道我需要运行npm installnpm init

However my npm install won't fix the issue, and the npm init does create the package.json file, BUT won't fix the issue. However my npm install won't fix the issue, and the npm init does create the package.json file, BUT won't fix the issue.

Also, after running npm init , it says I don't have the "start" script, and even after I set up the script, it won't work.另外,运行npm init后,它说我没有“启动”脚本,即使我设置了脚本,它也不起作用。

I've already:我已经:

  1. Deleted all.json files and ran npm install.删除所有.json 文件并运行 npm 安装。
  2. ran npm init and added the "start" script.运行 npm init 并添加“启动”脚本。
  3. rebooted my pc.重新启动了我的电脑。
  4. uninstalled and reinstalled VS Code.卸载并重新安装VS Code。
  5. done the whole code again on another computer.在另一台计算机上再次完成整个代码。

I don't know what else to do.我不知道还能做什么。

First off let me say you do not need npm or live server to view a simple HTML, CSS and JS project.首先让我说您不需要 npm 或实时服务器来查看简单的 HTML、CSS 和 JS 项目。 You can just open the HTML file using your web browser.您可以使用 web 浏览器打开 HTML 文件。 Assuming you know that let me cover what the npm commands are doing because it confused me at first.假设您知道,让我介绍一下 npm 命令正在做什么,因为它起初让我感到困惑。

  • npm init sets up a new or existing package. npm init 设置一个新的或现有的 package。 (creates package.json) (创建 package.json)
  • npm install will install all the required packages for your current project (dependencies from package.json) npm install 将为您当前的项目安装所有必需的包(来自 package.json 的依赖项)

The start command in your package.json is just the bit of code that gets run when you actually type npm start. package.json 中的启动命令只是当您实际键入 npm start 时运行的代码位。 Basically what it all comes down to is you do not need to run any sort of start command unless your application needs to run on a server which a simple HTML CSS and JS does not.基本上,这一切都归结为您不需要运行任何类型的启动命令,除非您的应用程序需要在简单的 HTML CSS 和 JS 不需要的服务器上运行。

Live Server is similar to what happens when you run the start command it is just an extension offered through VSCode. Live Server 类似于运行 start 命令时发生的情况,它只是通过 VSCode 提供的扩展。 Another useful extension I use is "Open in default browser" for my basic HTML CSS and JS files.我使用的另一个有用的扩展是“在默认浏览器中打开”,用于我的基本 HTML CSS 和 JS 文件。

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

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