应用未使用Webpack AOT为Prd构建本机脚本

时间:2019-07-08 14:05:23

标签: webpack nativescript

尝试在激活webpack和AOT的情况下为PRD构建应用程序时出现错误。

如果我禁用AOT,则应用程序构建过程成功,但是无法打开该应用程序(错误提示应用程序应关闭)。 我可以使它禁用webpack,但是我想那不是应该的...

对于开发流程,我使用带有tns run android的webpack来运行应用程序。

使用webpack和AOT构建时出现的错误是:

[19-07-08 10:57:31.698] (CLI) ERROR in : TypeError: workaroundResolveModule.workaroundResolve is not a function
[19-07-08 10:57:31.698] (CLI) ERROR in ../$$_lazy_route_resource lazy namespace object
[19-07-08 10:57:31.698] (CLI) Module not found: Error: Can't resolve '/mypath/src/app/routes/payment/payment.module.ngfactory.js' in '/mypath/$$_lazy_route_resource'
[19-07-08 10:57:31.698] (CLI)  @ ../$$_lazy_route_resource lazy namespace object ~/app/routes/payment/payment.module.ngfactory
[19-07-08 10:57:31.698] (CLI)  @ ../node_modules/@angular/core/fesm5/core.js
[19-07-08 10:57:31.698] (CLI)  @ ../platforms/android/app/snapshot-entry.js
[19-07-08 10:57:31.698] (CLI) ERROR in ../$$_lazy_route_resource lazy namespace object
[19-07-08 10:57:31.698] (CLI) Module not found: Error: Can't resolve '/mypath/src/app/routes/user/user.module.ngfactory.js' in '/mypath/$$_lazy_route_resource'
[19-07-08 10:57:31.698] (CLI)  @ ../$$_lazy_route_resource lazy namespace object ~/app/routes/user/user.module.ngfactory
[19-07-08 10:57:31.698] (CLI)  @ ../node_modules/@angular/core/fesm5/core.js
[19-07-08 10:57:31.698] (CLI)  @ ../platforms/android/app/snapshot-entry.js
[19-07-08 10:57:31.809] Build failed. Executing webpack failed with exit code 2.

2 个答案:

答案 0 :(得分:0)

我已通过“修复”与角度模块匹配的版本来解决此问题。

我的项目位于angular @ 7,但由于某种原因,@ angular / compiler-cli和@ ngtools / webpack在devDependencies中为8。

  

npm我@ ngtools / webpack @ ^ 7.2.4 @ angular / compiler-cli @ ^ 7.2.15

就我而言,也许您需要其他版本。 另外,我需要降级typescript@~3.1.1

答案 1 :(得分:0)

好吧...浪费了一天之后,解决方案非常简单...

显然,webpack不会加载代码中未提及或被迫加载的静态文件...

为了加载静态文件,您需要将其添加到webpack.config.js文件中。 我需要将此行添加到CopyWebpackPlugin

{ from: { glob: "assets/i18n/*.json" } },

所以CopyWebpackPluging是:

new CopyWebpackPlugin([
                { from: { glob: "assets/i18n/*.json" } },
                { from: { glob: "fonts/**" } },
                { from: { glob: "**/*.jpg" } },
                { from: { glob: "**/*.png" } },
            ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),

因此,当我现在运行应用程序时,我可以在控制台中看到以下行:

Successfully transferred en.json on device emulator-5554.

Source(请参阅捆绑工作流程部分)