Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to turn off minification? #65

Closed
ccorcos opened this issue Jun 24, 2016 · 19 comments
Closed

How to turn off minification? #65

ccorcos opened this issue Jun 24, 2016 · 19 comments

Comments

@ccorcos
Copy link

ccorcos commented Jun 24, 2016

    htmlLoader: {
      minimize: false,
    },

doesnt seem to work

@ccorcos
Copy link
Author

ccorcos commented Jun 24, 2016

These defaults are terrible:

https://github.com/webpack/html-loader/blob/master/index.js#L71-L88

<!DOCTYPE html> <html lang=en> <head> <meta charset=UTF-8> <title>Skeleton App</title> <meta name=viewport content="width=device-width,initial-scale=1"> </head> <body> <div id=root></div> <img src=<%=ROOT_URL%>/7d3f8da0eae1b0de9b3e8ef7ac4615b4.png /> <script type="text/javascript" src="<%=ROOT_URL%>/index-542e410e44a0f3d636e0.js"></script></body> </html>

@ccorcos
Copy link
Author

ccorcos commented Jun 24, 2016

I think it would be great if they were configurable but I cant figure out how to do that. Perhaps its a porblem with using it inside HtmlWebpackPlugin

@toverux
Copy link

toverux commented Jun 30, 2016

I use it this way, and that works :

{ test: /\.html$/, loader: 'html?minimize=false', exclude: [root('src', 'index.html')] },

https://github.com/webpack/html-loader/blob/master/index.js#L68

And yes, I agree, these are very destructive defaults :/

@ccorcos
Copy link
Author

ccorcos commented Jun 30, 2016

hmm. the problem is I'm using it with the Webpack HTML Plugin...

@toverux
Copy link

toverux commented Jun 30, 2016

Me too :) And the HtmlWebpackPlugin does not seem to cause any problem here, it's just html-loader's minimification, at least in my configuration (note that I also have excluded index.html in html-loader's configuration):

const BASE_CONFIG = {
    plugins: [
        new HtmlWebpackPlugin({ template: 'src/index.html' })
    ],

    module: {
        loaders: [
            { test: /\.html$/, loader: 'html?minimize=false', exclude: [root('src', 'index.html')] }
        ]
    }
};

@imvetri
Copy link

imvetri commented Jul 3, 2016

You can try the following? Please dont mind. i didnt try the code, I could guess this from the code
https://github.com/webpack/html-loader/blob/master/index.js#L68 difference.

htmlLoader:{"removeComments : false",
"removeCommentsFromCDATA : false",
"removeCDATASectionsFromCDATA : false",
"collapseWhitespace : false",
"conservativeCollapse : false",
"removeAttributeQuotes : false",
"useShortDoctype : false",
"keepClosingSlash : false",
"minifyJS : false",
"minifyCSS : false",
"removeScriptTypeAttributes : false",
"removeStyleTypeAttributes : false"}

@imvetri
Copy link

imvetri commented Jul 3, 2016

@ccorcos Can i request something? Could you share information on How you specifically opened the code difference at https://github.com/webpack/html-loader/issues/url ?

Above comment is my first comment on a open source 💃 yay. and i am curious how you were able to point at specific piece of code.

@ccorcos
Copy link
Author

ccorcos commented Jul 5, 2016

So I'm using the html webpack plugin like this:

      new HtmlWebpackPlugin({
        template: `!html!${config.html}`,
        inject: 'body',
      }),

It appears that adding any inline query params causes errors, and when I use something like...

    htmlLoader: {
      removeComments: false,
      removeCommentsFromCDATA: false,
      removeCDATASectionsFromCDATA: false,
      collapseWhitespace: false,
      conservativeCollapse: false,
      removeAttributeQuotes: false,
      useShortDoctype: false,
      keepClosingSlash: false,
      minifyJS: false,
      minifyCSS: false,
      removeScriptTypeAttributes: false,
      removeStyleTypeAttributes: false
    },

... it doesnt work either.

@imvetri When you are looking at code on github, click a line number and it it will get highlighted and change the url. You can also shift-click to another location to highlight a range.

@jackyon
Copy link

jackyon commented Jul 17, 2016

not working for me either, the html code still get compressed..
is there any solution for this issue?

@imvetri
Copy link

imvetri commented Jul 17, 2016

Can someone help me understand with this condition
https://github.com/webpack/html-loader/blob/master/index.js#L68

I suspect this line and it is taking program control inside the IF block all ways.

Hence minify=true is not working?

@ccorcos
Copy link
Author

ccorcos commented Jul 19, 2016

Whats going on is there are two configurations to effectively turn on minification. One is the htmlLoader field. so if you put htmlLoader: { minimize: false }, then that will override this.minimize which I believe is set when running webpack -p

@abelokon
Copy link

abelokon commented Jul 29, 2016

+1 same problem using HtmlWebpackPlugin - any updates?

@ccorcos
Copy link
Author

ccorcos commented Jul 29, 2016

I didnt figure anything out -- at then end of the day, it does work...

@joshwiens
Copy link
Member

@abelokon There are a few "problems" mentioned here. The original was the defaults for html loader in regards to minification which has been changed. The second was effectively minifing twice.

Could you be a bit more specific to which issue you are referencing?

@abelokon
Copy link

@d3viant0ne As already mentioned I'm also using HtmlWebpackPlugin and trying figure out how to turn off the minification of my html files. Since the first snippet posted here didn't work for me either, I agreed.

@eladchen
Copy link

eladchen commented Sep 26, 2016

FYI: Looking at this commit @ index.js:19

It seems that there is an issue with how "configKey" is looked up. The config key is looked up using
hasOwnProperty( ... ) on 'context.options' - This will never yield true, as the key does exists, but on 'context.options.prototype'.

Edit:
To overcome this alleged issue, the only way to provide options, is to use the syntax suggested in the loaders query parameters docs.

In order to disable minimizing, use:

loaders: [ {
    test:   /\.html$/,
    loader: 'html-loader',
    query:  {
        minimize: false
    }
} ]

Please correct me if I'm wrong.

@ghjagus
Copy link

ghjagus commented Nov 8, 2016

Is there a way that minimize the html string but keep case sensitive?Because i use PascalCase-style to name my components.

@hemanth
Copy link
Contributor

hemanth commented Mar 9, 2017

Thanks for reporting, this is fixed in #116.

@hemanth hemanth closed this as completed Mar 9, 2017
montehurd added a commit to wikimedia/wikimedia-page-library that referenced this issue May 4, 2018
Noticed on `enwiki > Javascript`. The collapsed tables borders were gone when using sepia or dark themes.

Caused by using the '-p' webpack switch, which caused the CSS to be minified ( webpack-contrib/html-loader#65 (comment) ), which changed the order of CSS, which was important. Specifically, the `ThemeTransform` CSS needs to be 1st, as outlined here https://github.com/wikimedia/wikimedia-page-library/blob/master/src/transform/index.js#L3 and here #128 (comment)
@amirhosein993
Copy link

I use it this way, and that works :

{ test: /\.html$/, loader: 'html?minimize=false', exclude: [root('src', 'index.html')] },

https://github.com/webpack/html-loader/blob/master/index.js#L68

And yes, I agree, these are very destructive defaults :/

where to write this?
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants