【问题标题】:Exclude unnecessary node modules from war从战争中排除不必要的节点模块
【发布时间】:2018-02-14 21:00:15
【问题描述】:

我正在创建一个使用 Maven、Spring、Hibernate、Angular 的 Web 应用程序。如果战争文件的大小非常大(151 MB),其中节点模块为 107 MB,请告诉我如何从战争文件中删除不必要的节点模块以保持其大小合理。 这是我的 npm 依赖项:

"dependencies": {
    "@angular/common": "~2.4.0",
    "@angular/compiler": "~2.4.0",
    "@angular/core": "~2.4.0",
    "@angular/forms": "~2.4.0",
    "@angular/http": "~2.4.0",
    "@angular/platform-browser": "~2.4.0",
    "@angular/platform-browser-dynamic": "~2.4.0",
    "@angular/router": "~3.4.0",
    "angular-in-memory-web-api": "~0.2.4",
    "angular2-datatable": "^0.6.0",
    "core-js": "^2.4.1",
    "lodash": "^4.17.4",
    "mydatepicker": "^1.6.1",
    "ng2-pdf-viewer": "^1.1.0",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
    "zone.js": "^0.7.4",
    "ng2-auto-complete": "^0.10.9"


  }

【问题讨论】:

    标签: angular npm maven-3 package.json


    【解决方案1】:

    我不知道你的目录结构是怎样的,但总的来说它应该通过在你的 .pom 中添加类似这样的东西来工作:

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
              <packagingExcludes>node_modules/**</packagingExcludes>
            </configuration>
          </plugin>
        </plugins>
      </build>
      ...
    </project>
    

    (见WAR Plugin Docs

    除了 node_modules/**,您还可以排除 src/**。我会检查 .war 文件,看看是否还有其他您可以排除的目录/文件。

    如果您的 Angular 应用程序打包在一个单独的 .jar 中,该 .jar 包含在 .war 中,这看起来会略有不同,例如:

    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/webapp</directory>
                <targetPath>META-INF/resources</targetPath>
                <excludes>
                    <exclude>node_modules/**</exclude>
                    <exclude>src/**</exclude>
                </excludes>
            </resource>
        </resources>
    </build>
    

    【讨论】:

    • 但是在那之后我会得到我的应用程序中需要的作为节点模块一部分的js文件吗??
    • 对不起,我刚刚假设您使用的是 angular-cli,是这样吗?如果是这样,angular-cli 会将您的所有代码、资产和东西打包到“dist”文件夹中,并且捆绑的 .js(供应商、polyfills 等)文件将包含您的代码和应用程​​序所需的库代码。是这种情况还是您使用了另一种打包机制(webpack 左右)?
    • 我正在使用 systemJS。
    猜你喜欢
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 2014-11-10
    • 2019-10-26
    相关资源
    最近更新 更多