繁体   English   中英

Angular似乎将开发依赖项构建到通用捆绑包中?

[英]Angular seems to build dev dependencies into universal bundle?

我正在使用typegoose来统一我的接口和在约6个应用程序之间共享的数据库模式。 它可以帮助我保持数据结构的一致性。

现在这意味着我的Angular应用程序中的大多数类型/接口都来自外部项目。

因此,我有:

    "typegoose": "^5.9.0",
    "@types/mongoose": "^5.5.17",
    "mongoose": "^5.6.12",
    "@tlabs/models": "^1.7.13",

添加为开发依赖项。 一切正常,我什至可以构建,但是当我尝试使用通用构建时,我会看到以下警告:

WARNING in ./node_modules/mongoose/lib/index.js 11:28-64
Critical dependency: the request of a dependency is an expression

关于mongodb / mongoose的x5倍

当我检查lambda函数日志时,我可以看到:

2019-09-17T14:56:59.691Z undefined ERROR (node:8) DeprecationWarning: This Package got moved, please use `@hasezoey/typegoose` | github:hasezoey/typegoose

它来自typegoose,这让我感到困惑。

我100%仅使用类型,如果我尝试通过使用其中一种类型的类实例化一个类对象来使用它,则整个应用程序将根本无法工作。

我在这里关于webpack的配置缺少什么吗?

在处理角度通用数据库和其他SQL数据库时,我也遇到类似的错误。 但是,有一种解决方案至少对我有用。

那就是webpack-node-externals包。 这只是使webpack忽略了您的node_modules文件夹。

链接到NPM页面>> https://www.npmjs.com/package/webpack-node-externals

假设webpack.server.config.js其他所有内容都可以解决这些错误,并使捆绑包的尺寸小得多。 (请记住,在部署到其他环境时,您将需要包括node_modules文件夹)

简要教程

  1. npm i webpack-node-externals
  2. 在文本编辑器中打开webpack.server.config.js
  3. 格式化该文件,使其看起来与此类似:
module.exports = env => {
  return {
    mode: "production",
    entry: {
      // This is our Express server for Dynamic universal
      server: "./server.ts"
    },
    externals: {
      "./dist/server/main": 'require("./server/main")'
    },
    target: "node",
    node: {
      __dirname: false,
      __filename: false
    },
    externals: [nodeExternals()], // <======LOOK HERE======|
    resolve: { extensions: [".ts", ".js"] },
    optimization: {
      minimize: false
    },
    output: {
      // Puts the output at the root of the dist folder
      path: path.join(__dirname, "dist"),
      filename: "[name].js"
    },
    module: {
      noParse: /polyfills-.*\.js/,
      rules: [
        { test: /\.ts$/, loader: "ts-loader" },
        {
          // Mark files inside `@angular/core` as using SystemJS style dynamic imports.
          // Removing this will cause deprecation warnings to appear.
          test: /(\\|\/)@angular(\\|\/)core(\\|\/).+\.js$/,
          parser: { system: true }
        }
      ]
    },
    plugins: [
      new webpack.ContextReplacementPlugin(
        // fixes WARNING Critical dependency: the request of a dependency is an expression
        /(.+)?angular(\\|\/)core(.+)?/,
        path.join(__dirname, "src"), // location of your src
        {} // a map of your routes
      ),
      new webpack.ContextReplacementPlugin(
        // fixes WARNING Critical dependency: the request of a dependency is an expression
        /(.+)?express(\\|\/)(.+)?/,
        path.join(__dirname, "src"),
        {}
      ),
    ]
  };
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM