gpt4 book ai didi

javascript - 使用文件加载器 outputPath 的 AOT 构建将 img 标签转换为字符串

转载 作者:行者123 更新时间:2023-11-30 21:06:01 24 4
gpt4 key购买 nike

我在尝试使用文件加载器构建 AOT 构建时遇到问题 outputPath选项。结果输出是 <img>标记用引号 ( "<img src=images/world.png alt=world />") 括起来。

这只发生在我的 AOT 构建中,而不是在我的开发构建中。所以我猜文件加载器在它的编译周期中被切断并插入了结果字符串。

版本:

Angular: 4.4.4
@ngtools/webpack: 1.7.2,
file-loader: 1.1.5,
image-webpack-loader: 3.4.2,
webpack: 3.6.0,
webpack-dev-server: 2.9.1

webpack.common.js |规则部分

   module: {
rules: [
{
test: /\.html$/,
loader: 'html-loader',
options: {
minimize: true,
caseSensitive: true
}
},
{
test: /\.scss$/,
exclude: /node_modules/,
loaders: ['raw-loader', 'sass-loader']
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
{
loader: 'file-loader', // Image loader
options: {
name: '[name].[ext]',
outputPath: 'images/' // Fails with AOT build. <img> tag gets turned into a string
}
},
{
loader: 'image-webpack-loader'
}
]
},
{
test: /\.(eot|woff2?|ttf)([?]?.*)$/, // Font loader
use: 'file-loader'
}
]
},

webpack.prod.js

module.exports = merge(common, {
module: {
rules: [
{
test: /\.ts$/,
loaders: ['@ngtools/webpack']
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({ // Uglyfy the JavaScript output | Still gives a small win with AOT build
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
compress: {
warnings: false,
screw_ie8: true
},
comments: false
}),
new AotPlugin({ // Create AOT build
tsConfigPath: './tsconfig.json',
entryModule: __dirname + '/src/app/app.module#AppModule'
}),
new webpack.DefinePlugin({ // Set the node env so that the project knows what to enable or disable
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
})
]
});

这是一个错误还是我做错了什么?如果它是一个错误,它在哪一边是错误,@ngtools/webpackfile-loader

感谢任何帮助!


我的app.html 供引用

<div>
<h1>Hello world</h1>
<img src="../assets/world.png" alt="world"/>
</div>

输出:

The output html


更新

貌似是Angular的AOT编译器的bug。所以我做了一个 Bug report on GitHub .下面的评论中有一个解决方法,但如果能修复此错误,那就太好了。

最佳答案

我认为这是一个错误。它呈现为字符串的原因是因为 URL 周围没有引号。

解决方法是通过 html-loader 插件添加引号:

{
test: /\.html$/, loader: 'html-loader', options: {
removeAttributeQuotes: false
}
}

有没有更好的解决方案?

关于javascript - 使用文件加载器 outputPath 的 AOT 构建将 img 标签转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46593269/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com