【问题标题】:Why does npm run eject look through all my project folders?为什么 npm runeject 会浏览我所有的项目文件夹?
【发布时间】:2019-08-21 09:39:18
【问题描述】:

我正在尝试在一个新项目上运行npm run eject,以便我可以配置 Webpack 文件,但我收到了以下消息:

✗ npm run eject

> location@0.1.0 eject /Users/danale/Projects/location
> react-scripts eject

NOTE: Create React App 2 supports TypeScript, Sass, CSS Modules and more without ejecting: https://reactjs.org/blog/2018/10/01/create-react-app-v2.html

? Are you sure you want to eject? This action is permanent. Yes
This git repository has untracked files or uncommitted changes:

为什么要引用所有项目文件夹?需要明确的是,我正在使用 CRA 创建的一个项目文件夹中运行上述命令。

我不在包含我所有项目的文件夹中,我在包含一个新创建项目的文件夹中。话虽如此,为什么 npm 引用了我所有的其他项目?

【问题讨论】:

    标签: npm webpack create-react-app


    【解决方案1】:

    在您退出使用create-react-app 创建的react 项目之前,它们会给您以下千篇一律的响应:

    NOTE: Create React App 2 supports TypeScript, Sass, CSS Modules and more without ejecting: https://reactjs.org/blog/2018/10/01/create-react-app-v2.html
    
    ? Are you sure you want to eject? This action is permanent. Yes
    This git repository has untracked files or uncommitted changes:
    

    原因是很多人希望对他们的webpack.config.js 文件有一个细粒度级别的控制,而你必须弹出才能访问该文件,因为它在内部被混淆了你的react-scripts 模块。现在弹出警告消息的一部分说:

    NOTE: Create React App 2 supports TypeScript, Sass, CSS Modules and more without ejecting: https://reactjs.org/blog/2018/10/01/create-react-app-v2.html
    

    是为了通知您,您不必弹出来利用预处理器、TypeScript 等......他们告诉您这是因为 create-react-app 并不总是支持轻松添加此功能,以便人们可以弹出以使用预处理器和TypeScript

    你是对的,为了使用SASS,你所要做的就是:

    1. 安装node-sass 模块:npm install node-sass
    2. 然后只需创建您的.scss 文件并在您希望使用样式的组件中导入您想要的.scss 文件。或者,您也可以只拥有一个“主”.scss 文件,其唯一工作是导入与您的应用相关的其他 .scss 文件。然后将这个“主”.scss 文件导入到您的 App.js 文件中。

    现在关于弹出警告信息的这一部分:

    This git repository has untracked files or uncommitted changes:
    

    您可能会得到这个,因为您已经为运行create-react-app CLI 的父文件夹设置了一个 git 存储库。基本上,在您的 create-react-app 接口所在的父文件夹之一中,有一个 .git/config 指向上游指向您的远程存储库之一。

    希望对您有所帮助!

    【讨论】:

      【解决方案2】:

      在我在错误消息中建议的文档中阅读的内容和修补它之间,您所要做的就是:

      npm install node-sass

      然后您可以开始将css 文件更改为scss 并为您的项目创建其他scss 文件。不需要npm run eject

      【讨论】:

        猜你喜欢
        • 2018-11-12
        • 2019-05-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-04
        • 2012-05-08
        • 2018-08-22
        相关资源
        最近更新 更多