From bf48112fa935e72473f9d0fca44bdb8504169e8b Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Wed, 20 Jan 2016 16:50:16 +0100 Subject: [PATCH] Use semistandard code style --- .jshintrc | 95 ------------ README.md | 6 +- examples/appcache/dist/bundle.js | 1 + examples/appcache/dist/manifest.appcache | 2 +- examples/appcache/example.js | 2 +- examples/appcache/webpack.config.js | 11 +- examples/custom-template/dist/bundle.js | 1 + examples/custom-template/example.js | 2 +- examples/custom-template/webpack.config.js | 2 +- examples/default/dist/bundle.js | 1 + examples/default/example.js | 2 +- examples/default/webpack.config.js | 2 +- examples/favicon/dist/bundle.js | 1 + examples/favicon/example.js | 2 +- examples/favicon/webpack.config.js | 2 +- examples/html-loader/dist/bundle.js | 1 + examples/html-loader/example.js | 2 +- examples/html-loader/webpack.config.js | 4 +- examples/jade-loader/dist/bundle.js | 7 +- examples/jade-loader/dist/index.html | 2 +- examples/jade-loader/example.js | 6 +- examples/jade-loader/time.jade | 2 +- examples/jade-loader/webpack.config.js | 4 +- examples/javascript/dist/bundle.js | 4 +- examples/javascript/dist/index.html | 2 +- examples/javascript/example.js | 2 +- examples/javascript/template.js | 2 +- examples/javascript/universial.js | 4 +- examples/javascript/webpack.config.js | 2 +- index.js | 121 +++++++-------- lib/compiler.js | 22 +-- lib/errors.js | 12 +- lib/loader.js | 2 +- package.json | 6 +- spec/ExampleSpec.js | 32 ++-- spec/HtmlWebpackPluginSpec.js | 166 +++++++++++---------- spec/fixtures/async.js | 2 +- spec/fixtures/common.js | 2 +- spec/fixtures/index.js | 4 +- spec/fixtures/theme.js | 2 +- spec/fixtures/util.js | 2 +- 41 files changed, 233 insertions(+), 316 deletions(-) delete mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 441ab5e..0000000 --- a/.jshintrc +++ /dev/null @@ -1,95 +0,0 @@ -{ - // From JSHint Default Configuration File - // See http://jshint.com/docs/ for more details - - "maxerr" : 50, // {int} Maximum error before stopping - - // Enforcing - "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) - "camelcase" : false, // true: Identifiers must be in camelCase - "curly" : true, // true: Require {} for every new block or scope - "eqeqeq" : true, // true: Require triple equals (===) for comparison - "forin" : false, // true: Require filtering for..in loops with obj.hasOwnProperty() - "freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc. - "immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` - "indent" : 2, // {int} Number of spaces to use for indentation - "latedef" : false, // true: Require variables/functions to be defined before being used - "newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()` - "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` - "noempty" : true, // true: Prohibit use of empty blocks - "nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters. - "nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment) - "plusplus" : false, // true: Prohibit use of `++` & `--` - "quotmark" : false, // Quotation mark consistency: - // false : do nothing (default) - // true : ensure whatever is used is consistent - // "single" : require single quotes - // "double" : require double quotes - "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) - "unused" : true, // true: Require all defined variables be used - "strict" : true, // true: Requires all functions run in ES5 Strict Mode - "maxparams" : false, // {int} Max number of formal params allowed per function - "maxdepth" : false, // {int} Max depth of nested blocks (within functions) - "maxstatements" : false, // {int} Max number statements per function - "maxcomplexity" : false, // {int} Max cyclomatic complexity per function - "maxlen" : false, // {int} Max number of characters per line - - // Relaxing - "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) - "boss" : false, // true: Tolerate assignments where comparisons would be expected - "debug" : false, // true: Allow debugger statements e.g. browser breakpoints. - "eqnull" : false, // true: Tolerate use of `== null` - "es5" : false, // true: Allow ES5 syntax (ex: getters and setters) - "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`) - "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features) - // (ex: `for each`, multiple try/catch, function expression…) - "evil" : false, // true: Tolerate use of `eval` and `new Function()` - "expr" : false, // true: Tolerate `ExpressionStatement` as Programs - "funcscope" : false, // true: Tolerate defining variables inside control statements - "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict') - "iterator" : false, // true: Tolerate using the `__iterator__` property - "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block - "laxbreak" : false, // true: Tolerate possibly unsafe line breakings - "laxcomma" : false, // true: Tolerate comma-first style coding - "loopfunc" : true, // true: Tolerate functions being defined in loops - "multistr" : false, // true: Tolerate multi-line strings - "noyield" : false, // true: Tolerate generator functions with no yield statement in them. - "notypeof" : false, // true: Tolerate invalid typeof operator values - "proto" : false, // true: Tolerate using the `__proto__` property - "scripturl" : false, // true: Tolerate script-targeted URLs - "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;` - "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation - "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;` - "validthis" : false, // true: Tolerate using this in a non-constructor function - - // Environments - "browser" : true, // Web Browser (window, document, etc) - "browserify" : false, // Browserify (node.js code in the browser) - "couch" : false, // CouchDB - "devel" : true, // Development/debugging (alert, confirm, etc) - "dojo" : false, // Dojo Toolkit - "jasmine" : false, // Jasmine - "jquery" : false, // jQuery - "mocha" : true, // Mocha - "mootools" : false, // MooTools - "node" : true, // Node.js - "nonstandard" : false, // Widely adopted globals (escape, unescape, etc) - "prototypejs" : false, // Prototype and Scriptaculous - "qunit" : false, // QUnit - "rhino" : false, // Rhino - "shelljs" : false, // ShellJS - "worker" : false, // Web Workers - "wsh" : false, // Windows Scripting Host - "yui" : false, // Yahoo User Interface - - // Custom Globals - "globals" : { - // jasmine helpers - "expect": false, - "describe": false, - "ddescribe": false, - "beforeEach": false, - "it": false, - "iit": false - } -} diff --git a/README.md b/README.md index f5cd012..6cc4fff 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ HTML Webpack Plugin =================== -[![npm version](https://badge.fury.io/js/html-webpack-plugin.svg)](http://badge.fury.io/js/html-webpack-plugin) [![Dependency Status](https://david-dm.org/ampedandwired/html-webpack-plugin.svg)](https://david-dm.org/ampedandwired/html-webpack-plugin) [![bitHound Score](https://www.bithound.io/github/ampedandwired/html-webpack-plugin/badges/score.svg)](https://www.bithound.io/github/ampedandwired/html-webpack-plugin) [![Build status](https://travis-ci.org/ampedandwired/html-webpack-plugin.svg)](https://travis-ci.org/ampedandwired/html-webpack-plugin) +[![npm version](https://badge.fury.io/js/html-webpack-plugin.svg)](http://badge.fury.io/js/html-webpack-plugin) [![Dependency Status](https://david-dm.org/ampedandwired/html-webpack-plugin.svg)](https://david-dm.org/ampedandwired/html-webpack-plugin) [![Build status](https://travis-ci.org/ampedandwired/html-webpack-plugin.svg)](https://travis-ci.org/ampedandwired/html-webpack-plugin) [![Windows build status](https://ci.appveyor.com/api/projects/status/github/ampedandwired/html-webpack-plugin)]() [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/Flet/semistandard) + +[![NPM](https://nodei.co/npm/html-webpack-plugin.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/html-webpack-plugin/) This is a [webpack](http://webpack.github.io/) plugin that simplifies creation of HTML files to serve your webpack bundles. This is especially useful for webpack bundles that include @@ -173,7 +175,7 @@ plugins: [ ``` You can use the lodash syntax out of the box. -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/feature/loaders/default_index.html) +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.ejs) as a starting point for writing your own. The `templateContent` option can also be a function to use another template language like jade: diff --git a/examples/appcache/dist/bundle.js b/examples/appcache/dist/bundle.js index 894c0ac..6e76564 100644 --- a/examples/appcache/dist/bundle.js +++ b/examples/appcache/dist/bundle.js @@ -49,6 +49,7 @@ h1.innerHTML = 'Hello world!'; document.body.appendChild(h1); + /***/ }, /* 1 */ /***/ function(module, exports) { diff --git a/examples/appcache/dist/manifest.appcache b/examples/appcache/dist/manifest.appcache index 9c520eb..150df1a 100644 --- a/examples/appcache/dist/manifest.appcache +++ b/examples/appcache/dist/manifest.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# 298aee4322ebd7ef62f9 +# 9e067d48ea3de65b9733 0714810ae3fb211173e2964249507195.png bundle.js diff --git a/examples/appcache/example.js b/examples/appcache/example.js index 13a1ca1..d62766b 100755 --- a/examples/appcache/example.js +++ b/examples/appcache/example.js @@ -1,4 +1,4 @@ require('./main.css'); var h1 = document.createElement('h1'); h1.innerHTML = 'Hello world!'; -document.body.appendChild(h1); \ No newline at end of file +document.body.appendChild(h1); diff --git a/examples/appcache/webpack.config.js b/examples/appcache/webpack.config.js index 3824f14..503cc88 100755 --- a/examples/appcache/webpack.config.js +++ b/examples/appcache/webpack.config.js @@ -12,7 +12,7 @@ module.exports = { loaders: [ { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') }, { test: /\.png$/, loader: 'file-loader' }, - { test: /\.html$/, loader: 'html-loader?-removeOptionalTags' }, + { test: /\.html$/, loader: 'html-loader?-removeOptionalTags' } ] }, plugins: [ @@ -20,11 +20,12 @@ module.exports = { new HtmlWebpackPlugin({ filename: 'index.html', template: 'template.html', - minify:{ - removeComments:true, - collapseWhitespace:true + minify: { + removeComments: true, + collapseWhitespace: true } }), new ExtractTextPlugin('styles.css') ] -}; \ No newline at end of file +}; + diff --git a/examples/custom-template/dist/bundle.js b/examples/custom-template/dist/bundle.js index 894c0ac..6e76564 100644 --- a/examples/custom-template/dist/bundle.js +++ b/examples/custom-template/dist/bundle.js @@ -49,6 +49,7 @@ h1.innerHTML = 'Hello world!'; document.body.appendChild(h1); + /***/ }, /* 1 */ /***/ function(module, exports) { diff --git a/examples/custom-template/example.js b/examples/custom-template/example.js index 13a1ca1..d62766b 100755 --- a/examples/custom-template/example.js +++ b/examples/custom-template/example.js @@ -1,4 +1,4 @@ require('./main.css'); var h1 = document.createElement('h1'); h1.innerHTML = 'Hello world!'; -document.body.appendChild(h1); \ No newline at end of file +document.body.appendChild(h1); diff --git a/examples/custom-template/webpack.config.js b/examples/custom-template/webpack.config.js index 7df9d54..967ddb2 100755 --- a/examples/custom-template/webpack.config.js +++ b/examples/custom-template/webpack.config.js @@ -19,4 +19,4 @@ module.exports = { }), new ExtractTextPlugin('styles.css') ] -}; \ No newline at end of file +}; diff --git a/examples/default/dist/bundle.js b/examples/default/dist/bundle.js index 3d11d80..21ab8de 100644 --- a/examples/default/dist/bundle.js +++ b/examples/default/dist/bundle.js @@ -49,6 +49,7 @@ h1.innerHTML = 'Hello world!'; document.body.appendChild(h1); + /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { diff --git a/examples/default/example.js b/examples/default/example.js index 13a1ca1..d62766b 100755 --- a/examples/default/example.js +++ b/examples/default/example.js @@ -1,4 +1,4 @@ require('./main.css'); var h1 = document.createElement('h1'); h1.innerHTML = 'Hello world!'; -document.body.appendChild(h1); \ No newline at end of file +document.body.appendChild(h1); diff --git a/examples/default/webpack.config.js b/examples/default/webpack.config.js index 69d8662..91326e3 100755 --- a/examples/default/webpack.config.js +++ b/examples/default/webpack.config.js @@ -15,4 +15,4 @@ module.exports = { plugins: [ new HtmlWebpackPlugin() ] -}; \ No newline at end of file +}; diff --git a/examples/favicon/dist/bundle.js b/examples/favicon/dist/bundle.js index 894c0ac..6e76564 100644 --- a/examples/favicon/dist/bundle.js +++ b/examples/favicon/dist/bundle.js @@ -49,6 +49,7 @@ h1.innerHTML = 'Hello world!'; document.body.appendChild(h1); + /***/ }, /* 1 */ /***/ function(module, exports) { diff --git a/examples/favicon/example.js b/examples/favicon/example.js index 13a1ca1..d62766b 100755 --- a/examples/favicon/example.js +++ b/examples/favicon/example.js @@ -1,4 +1,4 @@ require('./main.css'); var h1 = document.createElement('h1'); h1.innerHTML = 'Hello world!'; -document.body.appendChild(h1); \ No newline at end of file +document.body.appendChild(h1); diff --git a/examples/favicon/webpack.config.js b/examples/favicon/webpack.config.js index 5d96670..61e29b6 100755 --- a/examples/favicon/webpack.config.js +++ b/examples/favicon/webpack.config.js @@ -21,4 +21,4 @@ module.exports = { }), new ExtractTextPlugin('styles.css') ] -}; \ No newline at end of file +}; diff --git a/examples/html-loader/dist/bundle.js b/examples/html-loader/dist/bundle.js index 894c0ac..6e76564 100644 --- a/examples/html-loader/dist/bundle.js +++ b/examples/html-loader/dist/bundle.js @@ -49,6 +49,7 @@ h1.innerHTML = 'Hello world!'; document.body.appendChild(h1); + /***/ }, /* 1 */ /***/ function(module, exports) { diff --git a/examples/html-loader/example.js b/examples/html-loader/example.js index 13a1ca1..d62766b 100755 --- a/examples/html-loader/example.js +++ b/examples/html-loader/example.js @@ -1,4 +1,4 @@ require('./main.css'); var h1 = document.createElement('h1'); h1.innerHTML = 'Hello world!'; -document.body.appendChild(h1); \ No newline at end of file +document.body.appendChild(h1); diff --git a/examples/html-loader/webpack.config.js b/examples/html-loader/webpack.config.js index d53d289..cbeee16 100755 --- a/examples/html-loader/webpack.config.js +++ b/examples/html-loader/webpack.config.js @@ -11,7 +11,7 @@ module.exports = { loaders: [ { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') }, { test: /\.png$/, loader: 'file-loader' }, - { test: /\.html$/, loader: 'html-loader' }, + { test: /\.html$/, loader: 'html-loader' } ] }, plugins: [ @@ -27,4 +27,4 @@ module.exports = { }), new ExtractTextPlugin('styles.css') ] -}; \ No newline at end of file +}; diff --git a/examples/jade-loader/dist/bundle.js b/examples/jade-loader/dist/bundle.js index 927b894..b44cf0a 100644 --- a/examples/jade-loader/dist/bundle.js +++ b/examples/jade-loader/dist/bundle.js @@ -49,12 +49,13 @@ // Use the same template for the frontend code var template = __webpack_require__(5); - setInterval(function() { + setInterval(function () { var div = document.getElementById('main'); - div.innerHTML = template({ time: new Date()}); + div.innerHTML = template({ time: new Date() }); div.style.color = 'navy'; }, 1000); + /***/ }, /* 1 */ /***/ function(module, exports) { @@ -75,7 +76,7 @@ var jade_mixins = {}; var jade_interp; ;var locals_for_with = (locals || {});(function (time) { - buf.push("
Current time

" + (jade.escape((jade_interp = time.toTimeString()) == null ? '' : jade_interp)) + "

");}.call(this,"time" in locals_for_with?locals_for_with.time:typeof time!=="undefined"?time:undefined));;return buf.join(""); + buf.push("
Current time

" + (jade.escape((jade_interp = time.toISOString()) == null ? '' : jade_interp)) + "

");}.call(this,"time" in locals_for_with?locals_for_with.time:typeof time!=="undefined"?time:undefined));;return buf.join(""); } /***/ }, diff --git a/examples/jade-loader/dist/index.html b/examples/jade-loader/dist/index.html index f386988..e720b25 100644 --- a/examples/jade-loader/dist/index.html +++ b/examples/jade-loader/dist/index.html @@ -1 +1 @@ -Jade demo
Current time

00:00:00 GMT+0100 (CET)

\ No newline at end of file +Jade demo
Current time

1998-12-31T23:00:00.000Z

\ No newline at end of file diff --git a/examples/jade-loader/example.js b/examples/jade-loader/example.js index 6f4a05b..4770536 100755 --- a/examples/jade-loader/example.js +++ b/examples/jade-loader/example.js @@ -3,8 +3,8 @@ require('./main.css'); // Use the same template for the frontend code var template = require('./time.jade'); -setInterval(function() { +setInterval(function () { var div = document.getElementById('main'); - div.innerHTML = template({ time: new Date()}); + div.innerHTML = template({ time: new Date() }); div.style.color = 'navy'; -}, 1000); \ No newline at end of file +}, 1000); diff --git a/examples/jade-loader/time.jade b/examples/jade-loader/time.jade index 7dfa94b..a0ab69e 100644 --- a/examples/jade-loader/time.jade +++ b/examples/jade-loader/time.jade @@ -1,6 +1,6 @@ // this partial is used for frontend and backend .time b Current time - p #{time.toTimeString()} + p #{time.toISOString()} img(src="#{require('./logo.png')}") \ No newline at end of file diff --git a/examples/jade-loader/webpack.config.js b/examples/jade-loader/webpack.config.js index 3786711..3d27453 100755 --- a/examples/jade-loader/webpack.config.js +++ b/examples/jade-loader/webpack.config.js @@ -11,7 +11,7 @@ module.exports = { loaders: [ { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') }, { test: /\.png$/, loader: 'file-loader' }, - { test: /\.jade$/, loader: 'jade'} + { test: /\.jade$/, loader: 'jade' } ] }, plugins: [ @@ -23,4 +23,4 @@ module.exports = { }), new ExtractTextPlugin('styles.css') ] -}; \ No newline at end of file +}; diff --git a/examples/javascript/dist/bundle.js b/examples/javascript/dist/bundle.js index 5a71f59..29aa454 100644 --- a/examples/javascript/dist/bundle.js +++ b/examples/javascript/dist/bundle.js @@ -44,7 +44,7 @@ /* 0 */ /***/ function(module, exports, __webpack_require__) { - eval("__webpack_require__(1);\n\nvar universal = __webpack_require__(5);\nvar h1 = document.createElement('h1');\nh1.innerHTML = universal();\n\ndocument.body.appendChild(h1);\n\n/*****************\n ** WEBPACK FOOTER\n ** ./example.js\n ** module id = 0\n ** module chunks = 0\n **/\n//# sourceURL=webpack:///./example.js?"); + eval("__webpack_require__(1);\n\nvar universal = __webpack_require__(5);\nvar h1 = document.createElement('h1');\nh1.innerHTML = universal();\n\ndocument.body.appendChild(h1);\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./example.js\n ** module id = 0\n ** module chunks = 0\n **/\n//# sourceURL=webpack:///./example.js?"); /***/ }, /* 1 */ @@ -59,7 +59,7 @@ /* 5 */ /***/ function(module, exports) { - eval("// This file is used for frontend and backend\n'use strict';\n\n// If compiled by the html-webpack-plugin\n// HTML_WEBPACK_PLUGIN is set to true:\nvar backend = typeof HTML_WEBPACK_PLUGIN !== 'undefined';\n\nmodule.exports = function() {\n return 'Hello World from ' + (backend ? 'backend' : 'frontend');\n};\n\n/*****************\n ** WEBPACK FOOTER\n ** ./universial.js\n ** module id = 5\n ** module chunks = 0\n **/\n//# sourceURL=webpack:///./universial.js?"); + eval("// This file is used for frontend and backend\n'use strict';\n\n// If compiled by the html-webpack-plugin\n// HTML_WEBPACK_PLUGIN is set to true:\nvar backend = typeof HTML_WEBPACK_PLUGIN !== 'undefined';\n\nmodule.exports = function () {\n return 'Hello World from ' + (backend ? 'backend' : 'frontend');\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./universial.js\n ** module id = 5\n ** module chunks = 0\n **/\n//# sourceURL=webpack:///./universial.js?"); /***/ } /******/ ]); \ No newline at end of file diff --git a/examples/javascript/dist/index.html b/examples/javascript/dist/index.html index 186afc2..d1d7cd9 100644 --- a/examples/javascript/dist/index.html +++ b/examples/javascript/dist/index.html @@ -1,2 +1,2 @@ -Hello World from backendMon Jan 18 2016 13:50:36 GMT+0100 (CET)

Partial

+Hello World from backend2016-01-20T15:46:57.631Z

Partial

\ No newline at end of file diff --git a/examples/javascript/example.js b/examples/javascript/example.js index 5b71c95..e5aff3b 100644 --- a/examples/javascript/example.js +++ b/examples/javascript/example.js @@ -4,4 +4,4 @@ var universal = require('./universial.js'); var h1 = document.createElement('h1'); h1.innerHTML = universal(); -document.body.appendChild(h1); \ No newline at end of file +document.body.appendChild(h1); diff --git a/examples/javascript/template.js b/examples/javascript/template.js index 153d654..cbc7416 100644 --- a/examples/javascript/template.js +++ b/examples/javascript/template.js @@ -3,4 +3,4 @@ var partial = require('./partial.html'); var universal = require('./universial.js'); // Export a function / promise / or a string: -module.exports = universal() + new Date() + partial; +module.exports = universal() + new Date().toISOString() + partial; diff --git a/examples/javascript/universial.js b/examples/javascript/universial.js index 1e9f132..e63d688 100644 --- a/examples/javascript/universial.js +++ b/examples/javascript/universial.js @@ -5,6 +5,6 @@ // HTML_WEBPACK_PLUGIN is set to true: var backend = typeof HTML_WEBPACK_PLUGIN !== 'undefined'; -module.exports = function() { +module.exports = function () { return 'Hello World from ' + (backend ? 'backend' : 'frontend'); -}; \ No newline at end of file +}; diff --git a/examples/javascript/webpack.config.js b/examples/javascript/webpack.config.js index e468e7b..e0d314e 100644 --- a/examples/javascript/webpack.config.js +++ b/examples/javascript/webpack.config.js @@ -21,4 +21,4 @@ module.exports = { }), new ExtractTextPlugin('styles.css') ] -}; \ No newline at end of file +}; diff --git a/index.js b/index.js index ea831b3..30b057e 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ var childCompiler = require('./lib/compiler.js'); var prettyError = require('./lib/errors.js'); Promise.promisifyAll(fs); -function HtmlWebpackPlugin(options) { +function HtmlWebpackPlugin (options) { // Default options this.options = _.extend({ template: __dirname + '/default_index.ejs', @@ -26,23 +26,23 @@ function HtmlWebpackPlugin(options) { }, options); } -HtmlWebpackPlugin.prototype.apply = function(compiler) { +HtmlWebpackPlugin.prototype.apply = function (compiler) { var self = this; var isCompilationCached = false; var compilationPromise; this.options.template = this.getFullTemplatePath(this.options.template, compiler.context); - compiler.plugin('make', function(compilation, callback) { + compiler.plugin('make', function (compilation, callback) { // Compile the template (queued) compilationPromise = childCompiler.compileTemplate(self.options.template, compiler.context, self.options.filename, compilation) - .catch(function(err) { + .catch(function (err) { compilation.errors.push(prettyError(err, compiler.context).toString()); return { content: self.options.showErrors ? prettyError(err, compiler.context).toJsonHtml() : 'ERROR' }; }) - .then(function(compilationResult) { + .then(function (compilationResult) { // If the compilation change didnt change the cache is valid isCompilationCached = compilationResult.hash && self.hash === compilationResult.hash; self.hash = compilation.hash; @@ -51,13 +51,13 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { }); }); - compiler.plugin('after-compile', function(compilation, callback) { + compiler.plugin('after-compile', function (compilation, callback) { // Clear the compilation queue delete compiler.HtmlWebpackPluginQueue; callback(); }); - compiler.plugin('emit', function(compilation, callback) { + compiler.plugin('emit', function (compilation, callback) { var applyPluginsAsyncWaterfall = Promise.promisify(compilation.applyPluginsAsyncWaterfall, {context: compilation}); // Get all chunks var chunks = self.filterChunks(compilation.getStats().toJson(), self.options.chunks, self.options.excludeChunks); @@ -76,19 +76,19 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { Promise.resolve() // Favicon - .then(function() { + .then(function () { if (self.options.favicon) { return self.addFileToAssets(self.options.favicon, compilation) - .then(function(faviconBasename){ + .then(function (faviconBasename) { assets.favicon = faviconBasename; }); } }) // Wait for the compilation to finish - .then(function() { + .then(function () { return compilationPromise; }) - .then(function(compiledTemplate) { + .then(function (compiledTemplate) { // Allow to use a custom function / string instead if (self.options.templateContent) { return self.options.templateContent; @@ -98,33 +98,34 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { return self.evaluateCompilationResult(compilation, compiledTemplate); }) // Execute the template - .then(function(compilationResult) { + .then(function (compilationResult) { // If the loader result is a function execute it to retreive the html // otherwise use the returned html - return typeof compilationResult !== 'function' ? compilationResult : - self.executeTemplate(compilationResult, chunks, assets, compilation); + return typeof compilationResult !== 'function' + ? compilationResult + : self.executeTemplate(compilationResult, chunks, assets, compilation); }) // Allow plugins to change the html before assets are injected - .then(function(html) { + .then(function (html) { var pluginArgs = {html: html, assets: assets, plugin: self}; return applyPluginsAsyncWaterfall('html-webpack-plugin-before-html-processing', pluginArgs) - .then(function() { + .then(function () { return pluginArgs.html; }); }) - .then(function(html) { + .then(function (html) { // Add the stylesheets, scripts and so on to the resulting html return self.postProcessHtml(html, assets); }) // Allow plugins to change the html after assets are injected - .then(function(html) { + .then(function (html) { var pluginArgs = {html: html, assets: assets, plugin: self}; return applyPluginsAsyncWaterfall('html-webpack-plugin-after-html-processing', pluginArgs) - .then(function() { + .then(function () { return pluginArgs.html; }); }) - .catch(function(err) { + .catch(function (err) { // In case anything went wrong the promise is resolved // with the error message and an error is logged compilation.errors.push(prettyError(err, compiler.context).toString()); @@ -132,18 +133,18 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { self.hash = null; return self.options.showErrors ? prettyError(err, compiler.context).toHtml() : 'ERROR'; }) - .then(function(html) { + .then(function (html) { // Replace the compilation result with the evaluated html code compilation.assets[self.options.filename] = { - source: function() { + source: function () { return html; }, - size: function() { + size: function () { return html.length; } }; }) - .then(function(){ + .then(function () { // Let other plugins know that we are done: return applyPluginsAsyncWaterfall('html-webpack-plugin-after-emit', { html: compilation.assets[self.options.filename], @@ -151,21 +152,21 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { }); }) // Let webpack continue with it - .finally(function(){ + .finally(function () { callback(); // Tell blue bird that we don't want to wait for callback. // Fixes "Warning: a promise was created in a handler but none were returned from it" // https://github.com/petkaantonov/bluebird/blob/master/docs/docs/warning-explanations.md#warning-a-promise-was-created-in-a-handler-but-none-were-returned-from-it return null; }); - }); + }); }; /** * Evaluates the child compilation result * Returns a promise */ -HtmlWebpackPlugin.prototype.evaluateCompilationResult = function(compilation, source) { +HtmlWebpackPlugin.prototype.evaluateCompilationResult = function (compilation, source) { if (!source) { return Promise.reject('The child compilation didn\'t provide a result'); } @@ -181,9 +182,9 @@ HtmlWebpackPlugin.prototype.evaluateCompilationResult = function(compilation, so } catch (e) { return Promise.reject(e); } - return typeof newSource === 'string' || typeof newSource === 'function' ? - Promise.resolve(newSource) : - Promise.reject('The loader "' + this.options.template + '" didn\'t return html.'); + return typeof newSource === 'string' || typeof newSource === 'function' + ? Promise.resolve(newSource) + : Promise.reject('The loader "' + this.options.template + '" didn\'t return html.'); }; /** @@ -191,17 +192,17 @@ HtmlWebpackPlugin.prototype.evaluateCompilationResult = function(compilation, so * * Returns a promise */ -HtmlWebpackPlugin.prototype.executeTemplate = function(templateFunction, chunks, assets, compilation) { +HtmlWebpackPlugin.prototype.executeTemplate = function (templateFunction, chunks, assets, compilation) { var self = this; return Promise.resolve() // Template processing - .then(function() { + .then(function () { var templateParams = { webpack: compilation.getStats().toJson(), webpackConfig: compilation.options, htmlWebpackPlugin: { files: assets, - options: self.options, + options: self.options } }; var html = ''; @@ -220,14 +221,14 @@ HtmlWebpackPlugin.prototype.executeTemplate = function(templateFunction, chunks, * * Returns a promise */ -HtmlWebpackPlugin.prototype.postProcessHtml = function(html, assets) { +HtmlWebpackPlugin.prototype.postProcessHtml = function (html, assets) { var self = this; if (typeof html !== 'string') { return Promise.reject('Expected html to be a string but got ' + JSON.stringify(html)); } return Promise.resolve() // Inject - .then(function() { + .then(function () { if (self.options.inject) { return self.injectAssetsIntoHtml(html, assets); } else { @@ -235,7 +236,7 @@ HtmlWebpackPlugin.prototype.postProcessHtml = function(html, assets) { } }) // Minify - .then(function(html) { + .then(function (html) { if (self.options.minify) { var minify = require('html-minifier').minify; return minify(html, self.options.minify); @@ -247,23 +248,23 @@ HtmlWebpackPlugin.prototype.postProcessHtml = function(html, assets) { /* * Pushes the content of the given filename to the compilation assets */ -HtmlWebpackPlugin.prototype.addFileToAssets = function(filename, compilation) { +HtmlWebpackPlugin.prototype.addFileToAssets = function (filename, compilation) { filename = path.resolve(compilation.compiler.context, filename); return Promise.props({ size: fs.statAsync(filename), source: fs.readFileAsync(filename) }) - .catch(function() { + .catch(function () { return Promise.reject(new Error('HtmlWebpackPlugin: could not load file ' + filename)); }) - .then(function(results) { + .then(function (results) { var basename = path.basename(filename); compilation.fileDependencies.push(filename); compilation.assets[basename] = { - source: function() { + source: function () { return results.source; }, - size: function() { + size: function () { return results.size.size; } }; @@ -274,10 +275,10 @@ HtmlWebpackPlugin.prototype.addFileToAssets = function(filename, compilation) { /** * Helper to sort chunks */ -HtmlWebpackPlugin.prototype.sortChunks = function(chunks, sortMode) { +HtmlWebpackPlugin.prototype.sortChunks = function (chunks, sortMode) { // Sort mode auto by default: if (typeof sortMode === 'undefined' || sortMode === 'auto') { - return chunks.sort(function orderEntryLast(a, b) { + return chunks.sort(function orderEntryLast (a, b) { if (a.entry !== b.entry) { return b.entry ? 1 : -1; } else { @@ -301,7 +302,7 @@ HtmlWebpackPlugin.prototype.sortChunks = function(chunks, sortMode) { * Return all chunks from the compilation result which match the exclude and include filters */ HtmlWebpackPlugin.prototype.filterChunks = function (webpackStatsJson, includedChunks, excludedChunks) { - return webpackStatsJson.chunks.filter(function(chunk){ + return webpackStatsJson.chunks.filter(function (chunk) { var chunkName = chunk.names[0]; // This chunk doesn't have a name. This script can't handled it. if (chunkName === undefined) { @@ -324,14 +325,14 @@ HtmlWebpackPlugin.prototype.filterChunks = function (webpackStatsJson, includedC }); }; -HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, chunks) { +HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chunks) { var self = this; var webpackStatsJson = compilation.getStats().toJson(); // Use the configured public path or build a relative path - var publicPath = typeof compilation.options.output.publicPath !== 'undefined' ? - compilation.options.output.publicPath : - path.relative(path.dirname(self.options.filename), '.'); + var publicPath = typeof compilation.options.output.publicPath !== 'undefined' + ? compilation.options.output.publicPath + : path.relative(path.dirname(self.options.filename), '.'); if (publicPath.length && publicPath.substr(-1, 1) !== '/') { publicPath += '/'; @@ -345,7 +346,7 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, chun // Will contain all css files css: [], // Will contain the html5 appcache manifest files if it exists - manifest: Object.keys(compilation.assets).filter(function(assetFile){ + manifest: Object.keys(compilation.assets).filter(function (assetFile) { return path.extname(assetFile) === '.appcache'; })[0] }; @@ -363,13 +364,13 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, chun assets.chunks[chunkName] = {}; // Prepend the public path to all chunk files - var chunkFiles = [].concat(chunk.files).map(function(chunkFile) { + var chunkFiles = [].concat(chunk.files).map(function (chunkFile) { return publicPath + chunkFile; }); // Append a hash for cache busting if (this.options.hash) { - chunkFiles = chunkFiles.map(function(chunkFile) { + chunkFiles = chunkFiles.map(function (chunkFile) { return self.appendHash(chunkFile, webpackStatsJson.hash); }); } @@ -382,7 +383,7 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, chun assets.js.push(entry); // Gather all css files - var css = chunkFiles.filter(function(chunkFile){ + var css = chunkFiles.filter(function (chunkFile) { // Some chunks may contain content hash in their names, for ex. 'main.css?1e7cac4e4d8b52fd5ccd2541146ef03f'. // We must proper handle such cases, so we use regexp testing here return /^.css($|\?)/.test(path.extname(chunkFile)); @@ -401,13 +402,13 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, chun /** * Injects the assets into the given html string */ -HtmlWebpackPlugin.prototype.injectAssetsIntoHtml = function(html, assets) { +HtmlWebpackPlugin.prototype.injectAssetsIntoHtml = function (html, assets) { // Turn script files into script tags - var scripts = assets.js.map(function(scriptPath) { + var scripts = assets.js.map(function (scriptPath) { return ''; }); // Turn css files into link tags - var styles = assets.css.map(function(stylePath) { + var styles = assets.css.map(function (stylePath) { return ''; }); // Injections @@ -431,7 +432,7 @@ HtmlWebpackPlugin.prototype.injectAssetsIntoHtml = function(html, assets) { } if (body.length) { - if(bodyRegExp.test(html)) { + if (bodyRegExp.test(html)) { // Append assets to body element html = html.replace(bodyRegExp, function (match) { return body.join('') + match; @@ -448,7 +449,7 @@ HtmlWebpackPlugin.prototype.injectAssetsIntoHtml = function(html, assets) { if (!htmlRegExp.test(html)) { html = '' + html; } else { - html = html.replace(htmlRegExp, function(match) { + html = html.replace(htmlRegExp, function (match) { return match + ''; }); } @@ -483,15 +484,15 @@ HtmlWebpackPlugin.prototype.appendHash = function (url, hash) { return url + (url.indexOf('?') === -1 ? '?' : '&') + hash; }; -HtmlWebpackPlugin.prototype.getFullTemplatePath = function(template, context) { +HtmlWebpackPlugin.prototype.getFullTemplatePath = function (template, context) { // If the template doesn't use a loader use the lodash template loader - if(template.indexOf('!') === -1) { + if (template.indexOf('!') === -1) { template = require.resolve('./lib/loader.js') + '!' + path.resolve(context, template); } // Resolve template path return template.replace( /(\!)([^\/\\][^\!\?]+|[^\/\\!?])($|\?.+$)/, - function(match, prefix, filepath, postfix) { + function (match, prefix, filepath, postfix) { return prefix + path.resolve(filepath) + postfix; }); }; diff --git a/lib/compiler.js b/lib/compiler.js index ad38889..c118750 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -29,7 +29,7 @@ var SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin'); * } * */ -module.exports.compileTemplate = function compileTemplate(template, context, outputFilename, compilation) { +module.exports.compileTemplate = function compileTemplate (template, context, outputFilename, compilation) { // The entry file is just an empty helper as the dynamic template // require is added in "loader.js" var outputOptions = { @@ -50,31 +50,34 @@ module.exports.compileTemplate = function compileTemplate(template, context, out new SingleEntryPlugin(this.context, template), new LoaderTargetPlugin('node') ); - + // Fix for "Uncaught TypeError: __webpack_require__(...) is not a function" // Hot module replacement requires that every child compiler has its own // cache. @see https://github.com/ampedandwired/html-webpack-plugin/pull/179 - childCompiler.plugin('compilation', function(compilation) { - if(compilation.cache) { - if(!compilation.cache[compilerName]) + childCompiler.plugin('compilation', function (compilation) { + if (compilation.cache) { + if (!compilation.cache[compilerName]) { compilation.cache[compilerName] = {}; + } compilation.cache = compilation.cache[compilerName]; } }); // Compile and return a promise return new Promise(function (resolve, reject) { - childCompiler.runAsChild(function(err, entries, childCompilation) { + childCompiler.runAsChild(function (err, entries, childCompilation) { compilation.assets[outputOptions.filename] = cachedAsset; if (cachedAsset === undefined) { delete compilation.assets[outputOptions.filename]; } // Resolve / reject the promise if (childCompilation.errors && childCompilation.errors.length) { - var errorDetails = childCompilation.errors.map(function(error) { - return error.message + (error.error ? ':\n' + error.error: ''); - }).join('\n'); + var errorDetails = childCompilation.errors.map(function (error) { + return error.message + (error.error ? ':\n' + error.error : ''); + }).join('\n'); reject(new Error('Child compilation failed:\n' + errorDetails)); + } else if (err) { + reject(err); } else { resolve({ // Hash of the template entry point @@ -87,7 +90,6 @@ module.exports.compileTemplate = function compileTemplate(template, context, out }); }; - /** * Returns the child compiler name e.g. 'html-webpack-plugin for "index.html"' */ diff --git a/lib/errors.js b/lib/errors.js index 43a9464..ddf3562 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -4,20 +4,20 @@ var prettyError = new PrettyError(); prettyError.withoutColors(); prettyError.skipPackage(['html-plugin-evaluation']); prettyError.skipNodeFiles(); -prettyError.skip(function(traceLine) { +prettyError.skip(function (traceLine) { return traceLine.path === 'html-plugin-evaluation'; }); -module.exports = function(err, context) { +module.exports = function (err, context) { return { - toHtml: function() { + toHtml: function () { return 'Html Webpack Plugin:\n
\n' + this.toString() + '
'; }, - toJsonHtml: function() { + toJsonHtml: function () { return JSON.stringify(this.toHtml()); }, - toString: function() { + toString: function () { return prettyError.render(err).replace(/webpack:\/\/\/\./g, context); } }; -}; \ No newline at end of file +}; diff --git a/lib/loader.js b/lib/loader.js index beeb0c6..2e11d88 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -8,7 +8,7 @@ module.exports = function (source) { if (this.cacheable) { this.cacheable(); } - var allLoadersButThisOne = this.loaders.filter(function(loader) { + var allLoadersButThisOne = this.loaders.filter(function (loader) { return loader.module !== module.exports; }); // This loader shouldn't kick in if there is any other loader diff --git a/package.json b/package.json index e1711ad..aacbdc6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "html-webpack-plugin", - "version": "2.6.5", + "version": "2.7.0", "description": "Simplifies creation of HTML files to serve your webpack bundles", "main": "index.js", "files": [ @@ -9,7 +9,7 @@ "lib/" ], "scripts": { - "pretest": "jshint *.js spec", + "pretest": "semistandard", "test": "jasmine-node --captureExceptions spec" }, "repository": { @@ -38,8 +38,8 @@ "html-loader": "^0.4.0", "jade-loader": "^0.8.0", "jasmine-node": "^1.14.5", - "jshint": "^2.9.1-rc2", "rimraf": "^2.5.0", + "semistandard": "^7.0.5", "style-loader": "^0.13.0", "underscore-template-loader": "^0.5.2", "url-loader": "^0.5.7", diff --git a/spec/ExampleSpec.js b/spec/ExampleSpec.js index 4c4cbf8..82840ac 100644 --- a/spec/ExampleSpec.js +++ b/spec/ExampleSpec.js @@ -1,3 +1,4 @@ +/* global describe, it, expect */ 'use strict'; // Workaround for css-loader issue @@ -13,20 +14,20 @@ var fs = require('fs'); var OUTPUT_DIR = path.join(__dirname, '../dist'); -function runExample(exampleName, done) { +function runExample (exampleName, done) { var examplePath = path.resolve(__dirname, '..', 'examples', exampleName); var exampleOutput = path.join(OUTPUT_DIR, exampleName); - rm_rf(exampleOutput, function(){ - var options = require (path.join(examplePath, 'webpack.config.js')); + rm_rf(exampleOutput, function () { + var options = require(path.join(examplePath, 'webpack.config.js')); options.context = examplePath; options.output.path = exampleOutput; - webpack(options, function(err) { + webpack(options, function (err) { var dircompare = require('dir-compare'); var res = dircompare.compareSync(path.join(examplePath, 'dist'), exampleOutput, {compareSize: true}); - res.diffSet.filter(function(diff) { + res.diffSet.filter(function (diff) { return diff.state === 'distinct'; - }).forEach(function(diff) { + }).forEach(function (diff) { expect(fs.readFileSync(path.join(diff.path1, diff.name1)).toString()) .toBe(fs.readFileSync(path.join(diff.path2, diff.name2)).toString()); }); @@ -38,35 +39,32 @@ function runExample(exampleName, done) { }); } -describe('HtmlWebpackPlugin Examples', function() { - - it('appcache example', function(done) { +describe('HtmlWebpackPlugin Examples', function () { + it('appcache example', function (done) { runExample('appcache', done); }); - it('custom-template example', function(done) { + it('custom-template example', function (done) { runExample('custom-template', done); }); - it('default example', function(done) { + it('default example', function (done) { runExample('default', done); }); - it('favicon example', function(done) { + it('favicon example', function (done) { runExample('favicon', done); }); - it('html-loader example', function(done) { + it('html-loader example', function (done) { runExample('html-loader', done); }); - it('jade-loader example', function(done) { + it('jade-loader example', function (done) { runExample('jade-loader', done); }); - it('javascript example', function(done) { + it('javascript example', function (done) { runExample('javascript', done); }); - - }); diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index 57c1cb3..c74e942 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -1,3 +1,4 @@ +/* global describe, it, beforeEach, expect */ 'use strict'; // Workaround for css-loader issue @@ -15,9 +16,9 @@ var HtmlWebpackPlugin = require('../index.js'); var OUTPUT_DIR = path.join(__dirname, '../dist'); -function testHtmlPlugin(webpackConfig, expectedResults, outputFile, done, expectErrors, expectWarnings) { +function testHtmlPlugin (webpackConfig, expectedResults, outputFile, done, expectErrors, expectWarnings) { outputFile = outputFile || 'index.html'; - webpack(webpackConfig, function(err, stats) { + webpack(webpackConfig, function (err, stats) { expect(err).toBeFalsy(); var compilationErrors = (stats.compilation.errors || []).join('\n'); if (expectErrors) { @@ -33,7 +34,7 @@ function testHtmlPlugin(webpackConfig, expectedResults, outputFile, done, expect } var outputFileExists = fs.existsSync(path.join(OUTPUT_DIR, outputFile)); expect(outputFileExists).toBe(true); - if(!outputFileExists) { + if (!outputFileExists) { return done(); } var htmlContent = fs.readFileSync(path.join(OUTPUT_DIR, outputFile)).toString(); @@ -50,12 +51,12 @@ function testHtmlPlugin(webpackConfig, expectedResults, outputFile, done, expect }); } -describe('HtmlWebpackPlugin', function() { - beforeEach(function(done) { +describe('HtmlWebpackPlugin', function () { + beforeEach(function (done) { rm_rf(OUTPUT_DIR, done); }); - it('generates a default index.html file for a single entry point', function(done) { + it('generates a default index.html file for a single entry point', function (done) { testHtmlPlugin({ entry: path.join(__dirname, 'fixtures/index.js'), output: { @@ -64,10 +65,9 @@ describe('HtmlWebpackPlugin', function() { }, plugins: [new HtmlWebpackPlugin()] }, [/[\s]*