Skip to content

Add support for complex config options - #46

Merged
jhnns merged 1 commit into
webpack:masterfrom
lukasgeiter:support-complex-config
Feb 15, 2016
Merged

Add support for complex config options#46
jhnns merged 1 commit into
webpack:masterfrom
lukasgeiter:support-complex-config

Conversation

@lukasgeiter

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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
@jhnns
jhnns merged commit 58bea83 into webpack:masterFeb 15, 2016
@jhnns

Copy link
Copy Markdown
Contributor

Shipped with 0.4.3

@lukasgeiter

Copy link
Copy Markdown
ContributorAuthor

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

@jhnns

Copy link
Copy Markdown
Contributor

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

@lukasgeiter

Copy link
Copy Markdown
ContributorAuthor

Good idea 👍

@luyixin

Copy link
Copy Markdown

Cool

@duenyang

duenyang commented Jan 7, 2018

Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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

Sign up for freeto 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

@lukasgeiter@jhnns@luyixin@duenyang@BertieGo@wdapp