【问题标题】:Do I need to include node_modules in the production ready project?我需要在生产就绪项目中包含 node_modules 吗?
【发布时间】:2021-10-04 03:09:10
【问题描述】:

如果我正在构建一个 WordPress 主题,我需要在完成的主题中包含 node_modules 文件夹还是仅用于开发?运行我的 git commit 时,我应该忽略 node_modules 文件夹吗?

【问题讨论】:

    标签: wordpress git gulp dev-to-production


    【解决方案1】:

    这取决于您使用节点模块的目的,但我假设因为您已标记gulp,您正在使用节点来处理资产。在我的例子中,我们使用 webpack 来编译 scss 和 javascript。

    例如,如果我们从 npm 导入...

    app.js

    const PluginExample = require( '@creator/plugin-name' );
    

    app.scss

    @import `~bootstrap/scss/functions`;
    

    在开发中,导入将从 node_modules 目录加载,但在生产中它被编译到同一个文件中,因此我们可以删除模块目录。

    您应该知道您使用节点的目的是什么,但是,您可以尝试在本地运行您的生产构建过程,删除node_modules 目录,然后看看会发生什么。

    【讨论】:

      猜你喜欢
      • 2021-08-15
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 2011-02-06
      • 2017-05-24
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      相关资源
      最近更新 更多