如何阻止 node_modules 文件夹进入 Play Framework 2.4 的目标目录

How to stop node_modules folder to go into target directory of Play Framework 2.4

我正在使用 play framework 2.4 我的应用程序在安装 UI 组件之前运行良好,例如 (grunt,ruby,npm,cpmpass)我对它们了解不多,但我的项目 UI 需要这些才能工作 Play 应用程序的 public 目录下有一个文件夹 node_modules,这导致太多时间 run/test 项目每当我给出 runtest 命令时,我看到很多文件夹正在

位置开始创建
playapp/target/web/classes/main/META-INF/resources/webjars/playapp/0.1.0-7708ad295b8fe2c87a28bdb6afa7c10401c12a61-SNAPSHOT/node_modules

我怎样才能避免这种情况? 这是我尝试过但没有用的一些解决方案

project/Grunt

import play.PlayRunHook
import sbt._

import java.net.InetSocketAddress

object Grunt {
  def apply(base: File): PlayRunHook = {

    object GruntProcess extends PlayRunHook {

      var process: Option[Process] = None

      override def beforeStarted(): Unit = {
        Process("grunt dist", base).run
      }

      override def afterStarted(addr: InetSocketAddress): Unit = {
        process = Some(Process("grunt watch", base).run)
      }

      override def afterStopped(): Unit = {
        process.map(p => p.destroy())
        process = None
      }
    }

    GruntProcess
  }
}

这里是 build.sbt 文件的一部分 编辑

   import Grunt._
import play.PlayImport.PlayKeys.playRunHooks

import play.sbt.PlayImport.PlayKeys.playRunHooks

lazy val gruntDirectory = baseDirectory {
    _ / "public"
}

excludeFilter := HiddenFileFilter -- ".tmp"

unmanagedResourceDirectories in Assets <+= gruntDirectory { _ / "dist"}

unmanagedResourceDirectories in Assets <+= gruntDirectory { _ / ".tmp"}

unmanagedResourceDirectories in Assets <+= gruntDirectory { _ / "bower_components"}

unmanagedResourceDirectories in Assets <+= gruntDirectory { _ / "node_modules"}

//this is for development environment
unmanagedResourceDirectories in Assets <+= gruntDirectory { _ / "src" / "app"}

playRunHooks <+= baseDirectory.map(base => Grunt(base))

但目标文件夹仍然充满了 node_modules 文件夹,它在 runtest 命令中创建了很多文件夹,请帮忙。 编辑

我已经添加了

unmanagedResourceDirectories in Assets <+= gruntDirectory { _ / "node_modules"}

这一行,但现在我明白了这个错误

[trace] Stack trace suppressed: run last playapp/web-assets:webExportedDirectory for the full output.
[error] (playapp/web-assets:webExportedDirectory) Duplicate mappings:
[error]     playapp/target/web/classes/main/META-INF/resources/webjars/arteciate/0.1.0-7708ad295b8fe2c87a28bdb6afa7c10401c12a61-SNAPSHOT/requirejs/require.js
[error] from
[error]     playapp/public/bower_components/requirejs/require.js
[error]         /home/sara/git/arteciate/public/node_modules/requirejs/require.js
[error]     playapp/target/web/classes/main/META-INF/resources/webjars/arteciate/0.1.0-7708ad295b8fe2c87a28bdb6afa7c10401c12a61-SNAPSHOT/requirejs/README.md
[error] from
[error]     playapp/public/bower_components/requirejs/README.md
[error]         playapp/public/node_modules/requirejs/README.md
[error] Total time: 5 s, completed Aug 8, 2017 5:09:17 PM

public文件夹有以下内容

app               bower.json  dist   Gruntfile.js   node_modules  README.md         test
bower_components  config      fonts  Gruntfile.js~  package.json  _SpecRunner.html

而且我想再问一个问题,我不知道这些 UI 组件,所以 UI 工具实际上如何像 npm, yeoman, bower, sass, grunt 一样工作,什么是 node_modules 以及它们的用途和 "do I actually need bower modules in my build process with sbt"

作为 scala 开发人员,我认为您对这些工具如何协同工作不太了解。首先,您需要了解这些工具的工作原理以及我们为什么需要它们。

我想你正在使用 YeomanG运行tBower, SASS(通过 Compass) 并通过 NPM(节点包管理器) 使用它们。

NPM(节点包管理器):

当我们在我们的机器上安装 node 时,它会被安装,它用于 install/run 您机器上来自 npm 存储库的不同软件工具。

约曼:

它是一个 web 脚手架工具,通过使用它我们可以通过选择任何工具组合来搭建我们的 web 应用程序(比如 angular + Requirejs + SASS + G运行t 等).通过将所有这些模块配置在一起节省了我们的时间,并且我们可以通过命令创建更多组件(即网页、控制器等),而不必担心已创建组件中的 configuring/embedding。约曼为我们做这件事。

G运行t:

它是一个 javascript 任务 运行。您可以通过 g运行t-cli 在 GruntFile.js 和 运行 中配置任务(您也需要安装它)。我们可以通过使用 watcher 来节省大量的开发时间,配置了自动任务,如编译、连接、minify/uglify、运行ning 测试用例、运行ning jshint/lint、编译 SASS/SCSS 变成 CSS 每当改变等

凉亭:

它用于 web 的自动依赖 management,这意味着您不必在需要时将所有库与项目一起发送 send/deploy 在任何服务器上,通过 bower ,您可以只用一个命令(即 bower install)安装所有依赖项,它从 bower.json 文件读取并安装所有列出的依赖项。 (内部使用 git)

指南针:

它是 SASS/SCSS 的编译器,用于将 SASS/SCSS 文件转换为纯 css 文件。 为什么要使用 SASS/SCSS ? ---> 我们可以使用变量,parent/child 概念,通过 SASS/SCSS 继承概念,它减少了我们的工作并且很容易更改 variables/parent 类 比更改普通 css 中每个元素的样式更节省我们的开发时间并提供更好的 management 机制。 (需要来自 ruby 的 gem 才能安装)

node_modules:

当我们需要为javascript使用一些自动任务时,我们需要通过npm安装它们(npm install),它读取形式package.json文件并安装 g运行t 或其他工具(gulp、Compass、yeoman 等)所需的 package.json 文件中列出的所有依赖项。我们也可以通过npm而不是bower来安装开发依赖。

你真的需要node_modules吗?

如果您将 bower 用于库的依赖性 management,那么我们可以为您的问题提供解决方法,您可以将 public 文件夹分开,即在主项目和 运行 g运行t 命令到 compile/build JS/CSS 文件,然后你可以将这些编译后的文件复制到你的 public 文件夹中(你可以通过 g[ 配置整个过程=110=]t 并且您不必单独管理它)然后您的项目目录中将不会有 node_modules 文件夹并且它不会被编译并且希望它会节省您的时间。