posthtml / posthtml-loader

PostHTML for Webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiled template issue

thewebartisan7 opened this issue · comments

commented

The compiled template are wrapped with module-exports = "...html code here..."

What am I doing wrong?

Screenshot 2022-01-21 at 10 37 48

commented

hmmm... after several try and changes, I think that I found how to solve this.

However, I am not sure.

I have two different html folders, one that use posthtml and one that it's not using posthtml.

So I have added two rules in webpack, which cause issue above.

By adding just single then it seem works.

But would be possible to have two different so that I can customize options for both?

Webpack rules:

// First html only without posthtml:
// {
      //   test: /(html-templates).*\.html$/,
      //   use: [
      //     {
      //       loader: "html-loader",
      //       options: {
      //         minimize: false,
      //         removeComments: true,
      //         collapseWhitespace: true,
      //         interpolate: true
      //       },
      //     },
      //   ],
      //   exclude: /node_modules/,
      // },

// For posthtml:
      {
        //test: /(posthtml-templates).*\.html$/, // This was used for differentiate the files that need to be processed by posthtml
        test: /\.html$/,
        use: [
          {
            loader: "html-loader",
            options: {
              minimize: false,
              removeComments: true,
              collapseWhitespace: true,
              interpolate: true
            },
          },
          {
            loader: "posthtml-loader",
            options: {
              //ident: 'posthtml',
              //parser: 'PostHTML Parser',
              plugins: [
                /* PostHTML Plugins */
                require('posthtml-extend')({
                  encoding: 'utf8', // Parent template encoding
                  root: './src/www/posthtml-templates/', // Path to parent template directory
                  //skipParse: false,
                })
              ]
            }
          }
        ]
      },

@thewebartisan7 It seems that you are talking about a set of files that you do not want to process?

For example:

{
  loader: "posthtml-loader",
  options: {
    exclude: ['test.html', 'posthtml-templates/*']
}
commented

Thanks for your reply. In the end I just leave all to be processed by posthtml.