willyelm / pug-html-loader

Pug HTML loader for webpack

Home Page:https://github.com/willyelm/pug-html-loader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't access data inside pug file

giacomoalonzi opened this issue · comments

Hello, i'm trying to import some data from pug-html-loader in this way

{
        test: /\.pug$/,
        exclude: ['/node_modules/'],
        use: ['html-loader', `pug-html-loader?${qs.stringify({
          options: {
            debug: !isProduction,
            pretty: true,
            data: {
              title: 'hello',
              home: require('./src/content/home.json')
            }
          }
        })}`]
      },

but when I try to access data inside pug file, for example:
p= data.title or p= data.home
nothing happen.

Anyone can help me?

Thank you so much

according to this #33 data is every time a empty object.

Hi @giacomoalonzi, Please use

p= title

instead

p= data.title

@willyelm thank you for reply, I did it but nothing happened, no data is visualized.

@willyelm ok fixed
I changed this

{
    test: /\.pug$/,
    exclude: ['/node_modules/'],
    use: ['html-loader', `pug-html-loader?${qs.stringify({
      options: {
        debug: !isProduction,
        pretty: true,
        data: {
          title: 'hello',
          home: require('./src/content/home.json')
        }
      }
    })}`]
  },

to this

{
        test: /\.pug$/,
        exclude: ['/node_modules/'],
        use: [
          'html-loader',
          {
            loader: 'pug-html-loader',
            query: {
              pretty: true,
              data: {
                title: 'hello',
                home: require('./src/content/home.json')
              }
            }
          }
        ]
      }

qs.stringify cause the issue.
Thank you :)