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

js&css cannot be injected into the HTML file @version 2 #135

Closed
xiaoyunchen opened this issue Dec 8, 2015 · 14 comments
Closed

js&css cannot be injected into the HTML file @version 2 #135

xiaoyunchen opened this issue Dec 8, 2015 · 14 comments
Labels

Comments

@xiaoyunchen
Copy link

this is my config:

new HtmlWebpackPlugin({                     
            favicon:'./src/img/favicon.ico',
            filename:'/view/index.html',    
            template:'./src/view/index.html',   
            inject:true,
            hash:true,  
            minify:{    
                removeComments:true,    
                collapseWhitespace:false    
            }
        })

the same config file,If I use the version 1.7,it works!
But when I update to version 2,js&css cannot be injected into the HTML file,and even more, collapseWhitespace option in the minify option is not works neither.please check it and thanks.

@jantimon
Copy link
Owner

Is this a duplicate of #128 ?

@xiaoyunchen
Copy link
Author

I checked the #128 issue before submit this one,and it's not the same.
I don't use any js template like jade but only plain HTML.
And I also attach this attribute removeOptionalTags=false for the html-loader,but the problems still exist.

So the new version is worked in your project?Or I missed something important?

@jantimon
Copy link
Owner

jantimon commented Jan 8, 2016

@xiaoyunchen could you please try if it works now?

@xiaoyunchen
Copy link
Author

SORRY!Reply so late.
And I checked this problem with version 2.6.1,the js&css files can be injected into the HTML file but another problem comes.
When I use html-webpack-plugin and UglifyJsPlugin (minify and ungify my JS files),the HTML looks like below:
qq 20160114152954
two head tags!

And this is part of my webpack config file:

plugins:[
        new webpack.ProvidePlugin({ 
            $: 'jquery'
        }),
        new ExtractTextPlugin("css/[name].css"),
        new webpack.optimize.UglifyJsPlugin({   
            compress: {
                warnings: false
            },
            except: ['$super', '$', 'exports', 'require']   
        }),
        new HtmlWebpackPlugin({                     
            favicon:'./src/img/favicon.ico', 
            filename:'/view/index.html',    
            template:'./src/view/index.html',   
            inject:true,    
            hash:true,  
            minify:{    
                removeComments:true,    
                collapseWhitespace:true 
            }
        })
    ]

and thx!

@jantimon
Copy link
Owner

Oh thanks for the bug report could you please show me the source of ./src/view/index.html ?

@xiaoyunchen
Copy link
Author

Yes,it's so simple:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Index主页</title>
        <meta name="author" content="https://github.com/xiaoyunchen/webpack"/>
        <meta name="date" content="2015-12-3"/>
        <meta name="description" content="for test"/>
        <!--
            comments here
        -->
    </head>
    <body>
        <p>
            <button id="btn">Add</button>
        </p>
        <!--
            another comment and should be removed
        -->
    </body>
</html>

@jantimon
Copy link
Owner

From: https://github.com/ampedandwired/html-webpack-plugin/tree/feature/loaders/examples/html-loader
This seems to be an html-loader bug

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Example template</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
  <img src="logo.png">
</body>
</html>

Now if you add the Uglify plugin the html-loader uses aggressive minfification:

<!DOCTYPE html><html lang=en><head><meta charset=utf-8><title>Example template</title><meta name=viewport content="width=device-width,initial-scale=1"><body><img src=0714810ae3fb211173e2964249507195.png>

As you can see it removes ALL closing html tags.

@xiaoyunchen
Copy link
Author

Yes,without the ending tags of html/body/head

@jantimon
Copy link
Owner

There is already an issue for that: webpack-contrib/html-loader#40 and a pull request:
webpack-contrib/html-loader#43

@jantimon jantimon reopened this Jan 14, 2016
@jantimon
Copy link
Owner

For now you can disable removeOptionalTags in your html loader configuration:

  { test: /\.html$/, loader: 'html-loader?-removeOptionalTags' },

@xiaoyunchen
Copy link
Author

OK,Thx for that and I will try this

@xiaoyunchen
Copy link
Author

the CSS cannot be injected either even disable removeOptionalTags option
but the JS file works normally

@jantimon
Copy link
Owner

Please see the examples folder :)

@lock
Copy link

lock bot commented Jun 1, 2018

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants