根据本教程,我已经更新了Angular 4至5,此后,我的构建在Webpack上失败了,并带有两个警告:
WARNING in ./node_modules/@angular/core/esm5/core.js
6553:15-36 Critical dependency: the request of a dependency is an expression
@ ./node_modules/@angular/core/esm5/core.js
@ ./ClientApp/boot.browser.ts
@ multi event-source-polyfill webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true ./ClientApp/boot.browser.ts
WARNING in ./node_modules/@angular/core/esm5/core.js
6573:15-102 Critical dependency: the request of a dependency is an expression
@ ./node_modules/@angular/core/esm5/core.js
@ ./ClientApp/boot.browser.ts
@ multi event-source-polyfill webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true ./ClientApp/boot.browser.ts
我经历了这个话题,但没有任何帮助(也许我错过了什么(。这就是我的webpack.config.vendor.js插件的外观:
plugins: [
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', Popper: 'popper.js' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
new webpack.ContextReplacementPlugin(/@angularb.*b(bundles|linker)/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/11580
new webpack.ContextReplacementPlugin(/angular(\|/)core(\|/)@angular/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/14898
new webpack.IgnorePlugin(/^vertx$/) // Workaround for https://github.com/stefanpenner/es6-promise/issues/100
]
我最初使用来自Visual Studio的.NET Core API的角模板。
当您使用现在随附VS 2017的较新的角模板时,您升级了Angular版本4至5.x.x.x,您需要运行以下命令以避免一些警告您会在编译时间。
webpack --config webpack.config.vendor.js
从命令提示下运行此功能时,在项目的根部删除了您在上面的OP中看到的警告。
这是在 wwwroot/dist/dist 文件夹中重建 vendor.js 文件,以根据已安装的Angular(和其他(NPM软件包进行更新。
您在WebPack文件的contextreplacementplugin中传递的表达式可能存在问题。
我更改了它
来自
new webpack.ContextReplacementPlugin(
/angular(\|/)core(\|/)@angular/,
helpers.root('src'),
{}
)
to
new webpack.ContextReplacementPlugin(
/@angular(\|/)core(\|/)(@angular|esm5)/,
helpers.root('src'),
{}
)
这对我有用。希望它能有所帮助:(