Skip to content

Commit 8e89ea2

Browse files
author
Jan Nicklas
committed
Use lodash to solve dependency issues for the fallback loader
1 parent 7f63ba8 commit 8e89ea2

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ HTML Webpack Plugin
55
This is a [webpack](http://webpack.github.io/) plugin that simplifies creation of HTML files to serve your
66
webpack bundles. This is especially useful for webpack bundles that include
77
a hash in the filename which changes every compilation. You can either let the plugin generate an HTML file for you or supply
8-
your own template (using [blueimp templates](https://github.com/blueimp/JavaScript-Templates)).
8+
your own template (using lodash/ejs templates.
99

1010
Installation
1111
------------
@@ -70,7 +70,7 @@ Allowed values are as follows:
7070
- `hash`: `true | false` if `true` then append a unique webpack compilation hash to all
7171
included scripts and css files. This is useful for cache busting.
7272
- `chunks`: Allows you to add only some chunks (e.g. only the unit-test chunk)
73-
- `excludeChunks`: Allows you to skip some chunks (e.g. don't add the unit-test chunk)
73+
- `excludeChunks`: Allows you to skip some chunks (e.g. don't add the unit-test chunk)
7474

7575
Here's an example webpack config illustrating how to use these options:
7676
```javascript
@@ -121,7 +121,7 @@ and favicon files into the markup.
121121
```javascript
122122
plugins: [
123123
new HtmlWebpackPlugin({
124-
title: 'Custom template',
124+
title: 'Custom template',
125125
template: 'my-index.html', // Load a custom template
126126
inject: 'body' // Inject all scripts into the body
127127
})
@@ -135,7 +135,7 @@ plugins: [
135135
<html>
136136
<head>
137137
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
138-
<title>{%=o.htmlWebpackPlugin.options.title}</title>
138+
<title><%= htmlWebpackPlugin.options.title %></title>
139139
</head>
140140
<body>
141141
</body>
@@ -153,7 +153,7 @@ plugins: [
153153
]
154154
```
155155

156-
You can use the [blueimp template](https://github.com/blueimp/JavaScript-Templates) syntax out of the box.
156+
You can use the lodash/ejs syntax out of the box.
157157
If the `inject` feature doesn't fit your needs and you want full control over the asset placement use the [default template](https://github.com/ampedandwired/html-webpack-plugin/blob/master/default_index.html)
158158
as a starting point for writing your own.
159159

default_index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="UTF-8">
5-
<title>{%=o.htmlWebpackPlugin.options.title %}</title>
5+
<title><%= htmlWebpackPlugin.options.title %></title>
66
</head>
77
<body>
88
</body>

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function HtmlWebpackPlugin(options) {
2727
}, options);
2828
// If the template doesn't use a loader use the blueimp template loader
2929
if(this.options.template.indexOf('!') === -1) {
30-
this.options.template = 'blueimp-tmpl!' + path.resolve(this.options.template);
30+
this.options.template = require.resolve('./loader.js') + '!' + path.resolve(this.options.template);
3131
}
3232
// Resolve template path
3333
this.options.template = this.options.template.replace(
@@ -302,7 +302,7 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, chun
302302

303303
// Use the configured public path or build a relative path
304304
var publicPath = typeof compilation.options.output.publicPath !== 'undefined' ?
305-
compilation.options.output.publicPath :
305+
compilation.options.output.publicPath :
306306
path.relative(path.dirname(self.options.filename), '.');
307307

308308
if (publicPath.length && publicPath.substr(-1, 1) !== '/') {

loader.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var _ = require('lodash');
2+
var loaderUtils = require('loader-utils');
3+
4+
module.exports = function (source) {
5+
'use strict';
6+
var allLoadersButThisOne = this.loaders.filter(function(loader) {
7+
return loader.module !== module.exports;
8+
});
9+
// This loader shouldn't kick in if there is any other loader
10+
if (allLoadersButThisOne.length > 0) {
11+
return source;
12+
}
13+
// Use underscore for a minimalistic loader
14+
if (this.cacheable) {
15+
this.cacheable();
16+
}
17+
var options = loaderUtils.parseQuery(this.query);
18+
var template = _.template(source, options);
19+
return 'module.exports = ' + template;
20+
};

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
},
4343
"dependencies": {
4444
"bluebird": "^2.9.25",
45-
"blueimp-tmpl": "^2.5.4",
46-
"blueimp-tmpl-loader": "0.0.3",
4745
"html-minifier": "^0.7.2",
46+
"loader-utils": "^0.2.10",
4847
"lodash": "~3.9.3",
4948
"raw-loader": "^0.5.1"
5049
}

spec/fixtures/webpackconfig.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Test</title>
66
</head>
77
<body>
8-
<p>Public path is {%=o.webpackConfig.output.publicPath%}</p>
9-
<script src="{%=o.htmlWebpackPlugin.files.chunks.app.entry%}"></script>
8+
<p>Public path is <%= webpackConfig.output.publicPath %></p>
9+
<script src="<%= htmlWebpackPlugin.files.chunks.app.entry %>"></script>
1010
</body>
1111
</html>

0 commit comments

Comments
 (0)