@ngtools \ webpack AOT无法正常工作,或在发射95%时冻结 [英] @ngtools\webpack AOT doesn't work OR freezes at 95% emitting

查看:303
本文介绍了@ngtools \ webpack AOT无法正常工作,或在发射95%时冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想让AOT与我的Webpack应用一起工作. (@ ngtools/webpack)

I've been stuck trying to get AOT working with my Webpack app. (@ngtools/webpack)

有人可以帮我吗?

它似乎可以正常工作,但是bundle.js仍然包含在bundle中. 此外,它仍在寻找我的所有.html文件,并在所有组件模板上获取404.

It appears to work, however, compiler.js is still included in the bundle. Also it is still looking for all of my .html files and getting 404 on all of the component templates.

据我所知,这并不是在做AOT的最佳部分吗?

So as far as I can tell it's not really doing the best parts of the AOT?

这里有什么可以照亮的,我被卡住了!

Can any shine any light here, I'm stuck!!

谢谢!

推荐答案

如果单个文件处理不当或根本没有加载,则发射95%时将出现无限循环.

If a single file is handled incorrectly OR not loaded at all, you'll get an infinite loop on 95% emitting.

更新:: 似乎有一个地方会吞没错误:

UPDATE:: It appears that there is one area where errors will get swallowed up:

reject(new Error('Child compilation failed:\n' + errorDetails));

这是@ngtools \ webpack \ src \ resource_loader.js的第57行 您将需要设置一个断点来调试或输出该错误详细信息,否则您将永远陷入AOT编译.

That is line 57 of @ngtools\webpack\src\resource_loader.js You'll want to put a breakpoint to debug or output that error details, or you'll be stuck on AOT compiling forever.

如果将来有人被卡住,就别说了,基本上,如果您陷入无限循环,那么您可能走在正确的轨道上.

Just going to leave this in case someone is stuck in the future, basically if you get stuck in an infinite loop you're probably on the right track..

我终于可以工作了,一路上有很多问题.

I finally have something working, there were so many issues along the way..

我不明白的主要问题是,我想,对于AoT,必须将所有文件加载到webpack中

The main thing that bit me that I didn't understand is, I guess, that for AoT, ALL YOUR FILES have to be loaded into webpack

这是module.rules配置,最终让我运行...

This is the module.rules config that finally got me running...

// Ahead of Time Compilation
[{ test: /\.ts$/, loader: '@ngtools/webpack', exclude: [/\.(spec)\.ts$/] },
// AoT requires all files to be loaded
{ test: /\.html$/, loader: 'html-loader' },
{ test: /\.css$/, loader: 'raw-loader' },
{
    test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
    loader: 'file-loader', options: { name: '[path][name].[ext]' }
}]

我添加了这个加载程序,它基本上只是将我的图像放回到它们存在的完全相同的位置.但是我想这会导致它们被正确打包.

I added this loader which basically just puts my images back into the exact same place they exist.. But I guess that causes them to be packaged correctly..

如果我不包括文件类型(或者在加载文件时出现某种错误,请参见下面的注释),那么我将陷入无限循环...

If I do not include a file type (or if there is some sort of error while loading a file see comment below) then I get caught in an infinite loop...

如果使用--progress --profile运行webpack,您会发现它陷入了95%的发射状态. 幕后发生的事情是某种绝对路径与相对路径的问题,它陷入了mkdirp的循环中.

If you run webpack with --progress --profile you will see that it gets stuck on 95% emitting. What's going on behind the scenes is some sort of absolute path vs relative path issue and it gets caught in a loop in mkdirp.

但是我想这是AoT的窍门,就是要确保您有一个用于所用每种文件类型的加载器.

But I guess the trick is for AoT, is to just make sure that you have a loader for EVERY file type that you are using.

这篇关于@ngtools \ webpack AOT无法正常工作,或在发射95%时冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆