[英]Webpack HTML bundling - how to remove white spaces and new lines?
在我的 AngularJS 項目中,我有一個 HTML 模板,其中 innerText 在一個新行中:
<button class="btn">
Click here
</button>
我使用 webpack 作為我的捆綁器。 我希望它修剪那些新行/空白。 我使用 HtmlWebpackPlugin + minify 嘗試了以下配置:
plugins: [
new webpack.optimize.CommonsChunkPlugin({names: ['vendor'], filename: 'js/[name].js'}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, '../client/index.html'),
filename: 'index.html',
inject: 'body',
minify: {
collapseWhitespace: true
}
}),
但它不起作用 - 結果 HTML 仍然有一個新行。 預期結果是:
<button class="btn">Click here</button>
知道如何刪除這些空格嗎?
**remove newlines**
/\r?\n|\r/g
let foo = 'bar\nbar';
foo = foo.replace(/\r?\n|\r/g, " "); /* replace all newlines with a space */
console.log(foo);
**remove all whitespaces**
var spacesString= "Do I have spaces?";
var noSpacesString= myString.replace(/ /g,'');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.