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

Add support for complex config options #46

Merged
merged 1 commit into from
Feb 15, 2016
Merged

Add support for complex config options #46

merged 1 commit into from
Feb 15, 2016

Conversation

lukasgeiter
Copy link
Contributor

This PR add's a second method for passing config parameters to loader. Specifying them in the webpack configuration. This is necessary in order to be able to pass more complex arguments to the html minifier. In my case I wanted to specify ignoreCustomFragments, which is an array containing regexes. This is currently not possible within a simple query string.

If this gets merged, developers will be able to specify the loader options like this:

// ...
htmlLoader: {
    ignoreCustomFragments: [/\{\{.*?}}/]
}
// ...   

The property name can be configured via query, it defaults to htmlLoader

html?config=htmlLoaderSuperSpecialConfig

@jhnns
Copy link
Member

jhnns commented Feb 15, 2016

Looks good, thank you 👍

I would bet that I've seen this getLoaderConfig function before... 😉

jhnns added a commit that referenced this pull request Feb 15, 2016
Add support for complex config options
@jhnns jhnns merged commit 58bea83 into webpack-contrib:master Feb 15, 2016
@jhnns
Copy link
Member

jhnns commented Feb 15, 2016

Shipped with 0.4.3

@lukasgeiter
Copy link
Contributor Author

Cool! 👍
And yes, you caught me... It's inspired (read copied) by the function used in sass-loader 😉

@jhnns
Copy link
Member

jhnns commented Feb 15, 2016

We should probably unify that:
webpack/loader-utils#23

@lukasgeiter
Copy link
Contributor Author

Good idea 👍

@luyixin
Copy link

luyixin commented Nov 10, 2016

Cool

@duenyang
Copy link

duenyang commented Jan 7, 2018

module:{}
htmlLoader: {
  ignoreCustomFragments: [/\{\{.*?}}/],
  root: path.resolve(__dirname, 'assets'),
  attrs: ['img:src', 'link:href']
}

it's not ok, For loader options: webpack 2 no longer allows custom properties in configuration.
Loaders should be updated to allow passing options via loader options in module.rules.
Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:

plugins: [
    new webpack.LoaderOptionsPlugin({
       // test: /\.xxx$/, // may apply this only for some modules
       options: {
         htmlLoader: ...
       }
   })
]

@BertieGo
Copy link

BertieGo commented Nov 7, 2018

Hi,now I got a problem,I have code like this:
${ require('html-loader!./common/progress.html') }

and I want to insert var into progress.html so I can decide some elements in progress.html show/hide ,
cloud I suppose like that:
${ require('html-loader?var!./common/progress.html') }
and in progress.html:
<% if var <div>...</div> =%>

@wdapp
Copy link

wdapp commented May 20, 2019

你好,我想问一下,如果我的html模板增加了 script标签,如何配置html-loader可以让script标签内的js代码不被字符串化,可以被解析成javascript代码呢

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

Successfully merging this pull request may close these issues.

6 participants