Angular似乎将开发依赖项构建到universal bundle中?
我正在使用typegoose来统一我的接口+数据库模式,这些模式在~6个应用程序之间共享。它帮助我保持数据结构的一致性 这意味着Angular应用程序中的大多数类型/接口都来自 因此,我有:Angular似乎将开发依赖项构建到universal bundle中?,angular,angular-universal,server-side-rendering,angular-webpack,Angular,Angular Universal,Server Side Rendering,Angular Webpack,我正在使用typegoose来统一我的接口+数据库模式,这些模式在~6个应用程序之间共享。它帮助我保持数据结构的一致性 这意味着Angular应用程序中的大多数类型/接口都来自 因此,我有: "typegoose": "^5.9.0", "@types/mongoose": "^5.5.17", "mongoose": "^5.6.12", "@tlabs/models": "^1.7.13", 添加为开发人员依赖项。一切正常,我甚至可以构建,但当我尝试使用un
"typegoose": "^5.9.0",
"@types/mongoose": "^5.5.17",
"mongoose": "^5.6.12",
"@tlabs/models": "^1.7.13",
添加为开发人员依赖项。一切正常,我甚至可以构建,但当我尝试使用universal构建时,我可以看到以下警告:
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%只使用as类型,如果我试图通过使用其中一种类型实例化一个类对象来使用它,整个应用程序将根本无法工作
这里的webpack配置有什么我不知道的吗?在处理angular universal和其他SQL数据库时,我也遇到了类似的错误。但是,有一个解决方案至少对我有效 这就是
webpack节点externals
包。这只会使webpack忽略您的节点\模块文件夹
链接到NPM页面>>
假设webpack.server.config.js中的所有其他内容都存在,这将解决这些错误,并使包的大小小得多。(请记住,在部署到其他环境时,您将需要包括您的node_modules文件夹)
简短教程
npm i网页包节点外部
在文本编辑器中打开webpack.server.config.js
将该文件格式化为类似于以下内容:
module.exports=env=>{
返回{
模式:“生产”,
条目:{
//这是我们的Dynamic universal Express服务器
服务器:“./server.ts”
},
外部:{
“/dist/server/main”:“require(“/server/main”)”
},
目标:“节点”,
节点:{
__dirname:false,
__文件名:false
},
外部:[nodeExternals()]//
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"),
{}
),
]
};
};