jaketrent / html-webpack-template

a better default template for html-webpack-plugin
MIT License
830 stars 139 forks source link

bodyHtmlSnippet not working for me #67

Closed JESii closed 6 years ago

JESii commented 6 years ago

I have the following definition in my webpack config:

      new HtmlWebpackPlugin({
        inject: false,
        template: require('html-webpack-template'),
        links: [
         {rel: "stylesheet", 
           href: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", 
          integrity: "sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u", 
          crossorigin: "anonymous"}, 
          {rel: "stylesheet", 
            href: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css",  
            integrity: "sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp",  
            crossorigin: "anonymous"}, 
          {rel: "stylesheet", 
            href: "https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css",          
           crosorigin: "anonymous"}, 
          {rel: "icon", type: "image/png", sizes: "32x32", href: "/favicon-32x32.png"}
        ],
        scripts: [
          {src: "https://code.jquery.com/jquery-3.2.1.min.js",
             integrity: "sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=", 
            crossorigin: "anonymous"}, 
          {src: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js",
             integrity: "sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa",
             crossorigin: "anonymous"}
        ],
        title: options.title,
        appMountId: options.appMountId,
        bodyHtmlSnippet: "<div id='demo'></div>"
      })

The "options" values are specified when this is called:

  parts.indexTemplate({
    title: 'Free Code Camp Exercises',
    appMountId: 'app'
  }),

Builds to webpack-dev-server and production all complete with no errors and I am able to display the app.

All parameters work just fine except, the body-snippet is not added.

What am I doing wrong?

jaketrent commented 6 years ago

Not sure what might be wrong offhand. @holyfirexx, does anything stick out to you?

holyfirexx commented 6 years ago

Sorry, didn't see this notification until today! I ran a quick test, and I can't reproduce your issue. Could you upload your generated html file?

Update: Actually, I even copied your exact code above and it worked perfectly. Definitely would help to see what your generated file looks like.

JESii commented 6 years ago

https://gist.github.com/JESii/b48aef8493dc73b70bdccee08b750d40

Thanks!

holyfirexx commented 6 years ago

Hmm. I honestly have no idea what could be going wrong. My only guess is that it has something to do with the way you are adding title and appMountId. Try hard coding those and see if it helps. When I copied your code I replaced those with random strings. That was the only difference and it all worked.

One more thought: The html snippets are a fairly new addition, could you be on an older version that doesn't have them?

jaketrent commented 6 years ago

@holyfirexx thanks for taking a look. if it worked for you, I'm going to assume something else is going on in the environment for now. I'll close for now. If you find more evidence that the problem is in the template, feel free to reopen this.

JESii commented 6 years ago

Probably the later version; I'm on the 5.6 version.

Thanks much!

holyfirexx commented 6 years ago

Definitely the version. html snippets weren't added until 6.1.