代码之家  ›  专栏  ›  技术社区  ›  Kim

带SSR的Angular 18:将优化设置为true会忽略脚本中加载的库

  •  1
  • Kim  · 技术社区  · 10 月前

    我的Angular 18应用程序在开发模式下使用SSR运行平稳。但是,当我切换到优化设置为true的生产模式时,应用程序无法定位 'igv.js' 文件,即使它已经包含在 angular.json 文件。

    配置部分:

      "configurations": {
        "production": {
          "budgets": [
            {
              "type": "anyComponentStyle",
              "maximumWarning": "6kb"
            }
          ],
          "optimization": true,
          "sourceMap": true,
          "namedChunks": true,
          "extractLicenses": true,
          "outputHashing": "all"
        },
        "development": {
          "optimization": false,
          "extractLicenses": false,
          "sourceMap": true
        }
      },
    

    脚本部分:

        "scripts": [
          "node_modules/swagger-ui-dist/swagger-ui-bundle.js",
          "node_modules/swagger-ui-dist/swagger-ui-standalone-preset.js",
          "igv.js"
        ],
    

    这就是我对IGV模块的调用方式。由于我使用的是SSR,我必须在客户端调用该文件。

     ngAfterViewInit() {
        if (this.isBrowser) {
          import('igv').then(igvModule => {
            const igv = igvModule.default;
            if (igv && typeof igv.createBrowser === 'function') {
              this.igvModule = igv;
            } else {
              console.error('igv.createBrowser is not a function');
            }
          }).catch(error => {
            console.error('Error loading igv module:', error);
          });
        }
      }
    

    关于可能遗漏的内容,有什么建议吗?

    1 回复  |  直到 10 月前
        1
  •  1
  •   Naren Murali    10 月前

    你能试着导入吗 igv 直接使用下面的导入并开始在您的组件上使用它?

    import igv from '../node_modules/igv/dist/igv.esm.js';
    

    Related github issue

    推荐文章