The minify:false is not generating a non-minified file
Expected behaviour
Generate a unminified file
Current behaviour
Setting the minify to true or false is still generating the same minified file.
Environment
Tell us which operating system you are using, as well as which versions of Node.js, npm, webpack, and html-webpack-plugin. Run the following to get it quickly:
OS: macOS
NodeJS: 8.9.1
NPM: 5.5.1
Webpack: 3.12.0
html-webpack-plugin: 3.1.0
Config
Copy the minimal webpack.config.js to produce this issue:
module.exports = {
entry: {
app: './app.js'
},
output: {
path: path.resolve(__dirname, '../dist'),
filename: 'assets/js/[name].[hash:7].bundle.js'
},
module: {
rules: [
...
]
}
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'views/index.pug',
inject: true,
minify: false
}),
]
}
Copy your template file if it is part of this issue:
My template is a pug file, is large, just a usual pug file.
Relevant Links
- If your project is public, link to the repo so we can investigate directly.
- BONUS POINTS: Create a minimal reproduction and upload it to GitHub. This will get you the fastest support.
Additional contex
Add any other context about the problem here.
Does it also reproduce for a small pug file?
Yes,
I created this little one
h1 yes
p Hi!
ul
li 1
li 2
li 3
And I got this result
<h1>yes</h1><p>Hi!</p><ul><li>1</li><li>2</li><li>3</li></ul>
Does your pug loader minify?
I only have this with the pug loader
{
test: /\.pug$/,
use: [
{
loader: 'pug-loader'
}
]
},
This is my webpack.config.js file
// Libraries
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
const CopyWebpackPlugin = require('copy-webpack-plugin');
// Files
const plugins = require('../postcss.config');
// Configuration
module.exports = env => {
env = env.NODE_ENV;
console.log('Environment: ', env);
return {
context: path.resolve(__dirname, '../src'),
entry: {
app: './app.js'
},
output: {
path: path.resolve(__dirname, '../dist'),
publicPath: '/',
filename: 'assets/js/[name].[hash:7].bundle.js'
},
devServer: {
contentBase: path.resolve(__dirname, '../src'),
},
resolve: {
extensions: ['.js'],
alias: {
source: path.resolve(__dirname, '../src'), // Relative path of src
images: path.resolve(__dirname, '../src/assets/images'), // Relative path of images
}
},
/*
Loaders with their configurations
*/
module: {
rules: [
{
test: /\.js$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: { presets: ['es2015'] }
}
]
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1,
sourceMap: true,
minimize: env === 'development' ? false : true
}
},
]
})
},
{
use: 'css-loader!sass-loader?sourceMap',
test: /\.(sass|scss)$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1,
sourceMap: true,
minimize: env === 'development' ? false : true
}
},
'postcss-loader?sourceMap',
'sass-loader?sourceMap'
]
})
},
{
test: /\.pug$/,
use: [
{
loader: 'pug-loader'
}
]
},
{
test: /\.(png|jpe?g|gif|svg|ico)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 3000,
name: 'assets/images/[name].[hash:7].[ext]'
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 5000,
name: 'assets/fonts/[name].[hash:7].[ext]'
}
},
]
},
plugins: [
new CopyWebpackPlugin([
{ from: '../manifest.json', to: 'manifest.json' },
{ from: '../browserconfig.xml', to: 'browserconfig.xml' },
{ from: 'assets/images/favicons/android-chrome-192x192.png', to: 'assets/images/android-chrome-192x192.png' },
{ from: 'assets/images/favicons/android-chrome-256x256.png', to: 'assets/images/android-chrome-256x256.png' },
{ from: 'assets/images/favicons/mstile-150x150.png', to: 'assets/images/mstile-150x150.png' }
]),
new ExtractTextPlugin({
filename: 'assets/css/[name].[hash:7].bundle.css',
allChunks: env === 'development' ? false : true
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor'
}),
/*
Pages
*/
// Index page
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'views/index.pug',
inject: true
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.$': 'jquery',
'window.jQuery': 'jquery'
}),
new WebpackNotifierPlugin({
title: 'Your project'
})
]
}
};
Hi :-)
This looks like it's due to the way pug works, rather than anything to do with html-webpack-plugin.
For example:
const pug = require('pug');
const template = `
h1 yes
p Hi!
ul
li 1
li 2
li 3
`;
console.log(pug.render(template));
// <h1>yes</h1><p>Hi!</p><ul><li>1</li><li>2</li><li>3</li></ul>
The output can be made more readable by using the pretty option, though the pug docs say it's not recommended:
console.log(pug.render(template, { pretty: true }));
// <h1>yes</h1>
// <p>Hi!</p>
// <ul>
// <li>1</li>
// <li>2</li>
// <li>3</li>
// </ul>
See: https://pugjs.org/api/reference.html#options https://github.com/pugjs/pug-loader#options
This work for me.
{
test: /\.pug$/,
loader: "pug-loader",
query: {
pretty: true
}
}