Use semistandard code style
This commit is contained in:
parent
a35e5e3b84
commit
bf48112fa9
95
.jshintrc
95
.jshintrc
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
HTML Webpack Plugin
|
||||
===================
|
||||
[](http://badge.fury.io/js/html-webpack-plugin) [](https://david-dm.org/ampedandwired/html-webpack-plugin) [](https://www.bithound.io/github/ampedandwired/html-webpack-plugin) [](https://travis-ci.org/ampedandwired/html-webpack-plugin)
|
||||
[](http://badge.fury.io/js/html-webpack-plugin) [](https://david-dm.org/ampedandwired/html-webpack-plugin) [](https://travis-ci.org/ampedandwired/html-webpack-plugin) []() [](https://github.com/Flet/semistandard)
|
||||
|
||||
[](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:
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
h1.innerHTML = 'Hello world!';
|
||||
document.body.appendChild(h1);
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 1 */
|
||||
/***/ function(module, exports) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
CACHE MANIFEST
|
||||
# 298aee4322ebd7ef62f9
|
||||
# 9e067d48ea3de65b9733
|
||||
|
||||
0714810ae3fb211173e2964249507195.png
|
||||
bundle.js
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
require('./main.css');
|
||||
var h1 = document.createElement('h1');
|
||||
h1.innerHTML = 'Hello world!';
|
||||
document.body.appendChild(h1);
|
||||
document.body.appendChild(h1);
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
h1.innerHTML = 'Hello world!';
|
||||
document.body.appendChild(h1);
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 1 */
|
||||
/***/ function(module, exports) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
require('./main.css');
|
||||
var h1 = document.createElement('h1');
|
||||
h1.innerHTML = 'Hello world!';
|
||||
document.body.appendChild(h1);
|
||||
document.body.appendChild(h1);
|
||||
|
|
|
|||
|
|
@ -19,4 +19,4 @@ module.exports = {
|
|||
}),
|
||||
new ExtractTextPlugin('styles.css')
|
||||
]
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
h1.innerHTML = 'Hello world!';
|
||||
document.body.appendChild(h1);
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 1 */
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
require('./main.css');
|
||||
var h1 = document.createElement('h1');
|
||||
h1.innerHTML = 'Hello world!';
|
||||
document.body.appendChild(h1);
|
||||
document.body.appendChild(h1);
|
||||
|
|
|
|||
|
|
@ -15,4 +15,4 @@ module.exports = {
|
|||
plugins: [
|
||||
new HtmlWebpackPlugin()
|
||||
]
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
h1.innerHTML = 'Hello world!';
|
||||
document.body.appendChild(h1);
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 1 */
|
||||
/***/ function(module, exports) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
require('./main.css');
|
||||
var h1 = document.createElement('h1');
|
||||
h1.innerHTML = 'Hello world!';
|
||||
document.body.appendChild(h1);
|
||||
document.body.appendChild(h1);
|
||||
|
|
|
|||
|
|
@ -21,4 +21,4 @@ module.exports = {
|
|||
}),
|
||||
new ExtractTextPlugin('styles.css')
|
||||
]
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
h1.innerHTML = 'Hello world!';
|
||||
document.body.appendChild(h1);
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 1 */
|
||||
/***/ function(module, exports) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
require('./main.css');
|
||||
var h1 = document.createElement('h1');
|
||||
h1.innerHTML = 'Hello world!';
|
||||
document.body.appendChild(h1);
|
||||
document.body.appendChild(h1);
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
]
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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("<!-- this partial is used for frontend and backend--><div class=\"time\"> <b>Current time</b><p>" + (jade.escape((jade_interp = time.toTimeString()) == null ? '' : jade_interp)) + "</p></div><img" + (jade.attr("src", "" + (__webpack_require__(8)) + "", true, true)) + ">");}.call(this,"time" in locals_for_with?locals_for_with.time:typeof time!=="undefined"?time:undefined));;return buf.join("");
|
||||
buf.push("<!-- this partial is used for frontend and backend--><div class=\"time\"> <b>Current time</b><p>" + (jade.escape((jade_interp = time.toISOString()) == null ? '' : jade_interp)) + "</p></div><img" + (jade.attr("src", "" + (__webpack_require__(8)) + "", true, true)) + ">");}.call(this,"time" in locals_for_with?locals_for_with.time:typeof time!=="undefined"?time:undefined));;return buf.join("");
|
||||
}
|
||||
|
||||
/***/ },
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<!DOCTYPE html><html><head><title>Jade demo</title><link rel="shortcut icon" href="favicon.ico"><link href="styles.css" rel="stylesheet"></head><body><div id="main"><!-- this partial is used for frontend and backend--><div class="time"> <b>Current time</b><p>00:00:00 GMT+0100 (CET)</p></div><img src="0714810ae3fb211173e2964249507195.png"></div><script src="bundle.js"></script></body></html>
|
||||
<!DOCTYPE html><html><head><title>Jade demo</title><link rel="shortcut icon" href="favicon.ico"><link href="styles.css" rel="stylesheet"></head><body><div id="main"><!-- this partial is used for frontend and backend--><div class="time"> <b>Current time</b><p>1998-12-31T23:00:00.000Z</p></div><img src="0714810ae3fb211173e2964249507195.png"></div><script src="bundle.js"></script></body></html>
|
||||
|
|
@ -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);
|
||||
}, 1000);
|
||||
|
|
|
|||
|
|
@ -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')}")
|
||||
|
|
@ -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')
|
||||
]
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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?");
|
||||
|
||||
/***/ }
|
||||
/******/ ]);
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
<head><link href="styles.css" rel="stylesheet"></head>Hello World from backendMon Jan 18 2016 13:50:36 GMT+0100 (CET)<h2>Partial</h2>
|
||||
<head><link href="styles.css" rel="stylesheet"></head>Hello World from backend2016-01-20T15:46:57.631Z<h2>Partial</h2>
|
||||
<img src="0714810ae3fb211173e2964249507195.png"><script src="bundle.js"></script>
|
||||
|
|
@ -4,4 +4,4 @@ var universal = require('./universial.js');
|
|||
var h1 = document.createElement('h1');
|
||||
h1.innerHTML = universal();
|
||||
|
||||
document.body.appendChild(h1);
|
||||
document.body.appendChild(h1);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -21,4 +21,4 @@ module.exports = {
|
|||
}),
|
||||
new ExtractTextPlugin('styles.css')
|
||||
]
|
||||
};
|
||||
};
|
||||
|
|
|
|||
121
index.js
121
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 '<script src="' + scriptPath + '"></script>';
|
||||
});
|
||||
// Turn css files into link tags
|
||||
var styles = assets.css.map(function(stylePath) {
|
||||
var styles = assets.css.map(function (stylePath) {
|
||||
return '<link href="' + stylePath + '" rel="stylesheet">';
|
||||
});
|
||||
// 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 = '<head></head>' + html;
|
||||
} else {
|
||||
html = html.replace(htmlRegExp, function(match) {
|
||||
html = html.replace(htmlRegExp, function (match) {
|
||||
return match + '<head></head>';
|
||||
});
|
||||
}
|
||||
|
|
@ -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;
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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"'
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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<pre>\n' + this.toString() + '</pre>';
|
||||
},
|
||||
toJsonHtml: function() {
|
||||
toJsonHtml: function () {
|
||||
return JSON.stringify(this.toHtml());
|
||||
},
|
||||
toString: function() {
|
||||
toString: function () {
|
||||
return prettyError.render(err).replace(/webpack:\/\/\/\./g, context);
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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()]
|
||||
}, [/<body>[\s]*<script src="index_bundle.js"><\/script>[\s]*<\/body>/], null, done);
|
||||
|
||||
});
|
||||
|
||||
it('generates a default index.html file with multiple entry points', function(done) {
|
||||
it('generates a default index.html file with multiple entry points', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
util: path.join(__dirname, 'fixtures/util.js'),
|
||||
|
|
@ -81,7 +81,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<script src="util_bundle.js"', '<script src="app_bundle.js"'], null, done);
|
||||
});
|
||||
|
||||
it('allows you to specify a custom loader', function(done) {
|
||||
it('allows you to specify a custom loader', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
app: path.join(__dirname, 'fixtures/index.js')
|
||||
|
|
@ -98,7 +98,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
['<script src="app_bundle.js', 'Some unique text'], null, done);
|
||||
});
|
||||
|
||||
it('should pass through loader errors', function(done) {
|
||||
it('should pass through loader errors', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
app: path.join(__dirname, 'fixtures/index.js')
|
||||
|
|
@ -115,7 +115,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
['ReferenceError: foo is not defined'], null, done, true);
|
||||
});
|
||||
|
||||
it('uses a custom loader from webpacks config', function(done) {
|
||||
it('uses a custom loader from webpacks config', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
app: path.join(__dirname, 'fixtures/index.js')
|
||||
|
|
@ -137,7 +137,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
['<script src="app_bundle.js', 'Some unique text'], null, done);
|
||||
});
|
||||
|
||||
it('works when using html-loader', function(done) {
|
||||
it('works when using html-loader', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
app: path.join(__dirname, 'fixtures/index.js')
|
||||
|
|
@ -154,7 +154,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
['<script src="app_bundle.js"'], null, done);
|
||||
});
|
||||
|
||||
it('allows you to specify your own HTML template file', function(done) {
|
||||
it('allows you to specify your own HTML template file', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
app: path.join(__dirname, 'fixtures/index.js')
|
||||
|
|
@ -275,7 +275,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<body>\n</body>'], null, done);
|
||||
});
|
||||
|
||||
it('allows you to specify your own HTML template function', function(done) {
|
||||
it('allows you to specify your own HTML template function', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {app: path.join(__dirname, 'fixtures/index.js')},
|
||||
output: {
|
||||
|
|
@ -283,7 +283,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
filename: 'app_bundle.js'
|
||||
},
|
||||
plugins: [new HtmlWebpackPlugin({
|
||||
templateContent: function() {
|
||||
templateContent: function () {
|
||||
return fs.readFileSync(path.join(__dirname, 'fixtures/plain.html'), 'utf8');
|
||||
}
|
||||
})]
|
||||
|
|
@ -291,7 +291,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
['<script src="app_bundle.js"'], null, done);
|
||||
});
|
||||
|
||||
it('works with source maps', function(done) {
|
||||
it('works with source maps', function (done) {
|
||||
testHtmlPlugin({
|
||||
devtool: 'sourcemap',
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
|
|
@ -303,7 +303,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<script src="index_bundle.js"'], null, done);
|
||||
});
|
||||
|
||||
it('handles hashes in bundle filenames', function(done) {
|
||||
it('handles hashes in bundle filenames', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -314,7 +314,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, [/<script src="index_bundle_[0-9a-f]+\.js"*/], null, done);
|
||||
});
|
||||
|
||||
it('allows to append hashes to the assets', function(done) {
|
||||
it('allows to append hashes to the assets', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -325,7 +325,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<script src="index_bundle.js?%hash%"'], null, done);
|
||||
});
|
||||
|
||||
it('allows to append hashes to the assets', function(done) {
|
||||
it('allows to append hashes to the assets', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -337,7 +337,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
});
|
||||
|
||||
it('should work with the css extract plugin', function (done) {
|
||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||
var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/theme.js'),
|
||||
output: {
|
||||
|
|
@ -351,13 +351,13 @@ describe('HtmlWebpackPlugin', function() {
|
|||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin(),
|
||||
new ExtractTextPlugin("styles.css")
|
||||
new ExtractTextPlugin('styles.css')
|
||||
]
|
||||
}, ['<link href="styles.css"'], null, done);
|
||||
});
|
||||
|
||||
it('should allow to add cache hashes to with the css assets', function (done) {
|
||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||
var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/theme.js'),
|
||||
output: {
|
||||
|
|
@ -371,13 +371,13 @@ describe('HtmlWebpackPlugin', function() {
|
|||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({hash: true}),
|
||||
new ExtractTextPlugin("styles.css")
|
||||
new ExtractTextPlugin('styles.css')
|
||||
]
|
||||
}, ['<link href="styles.css?%hash%"'], null, done);
|
||||
});
|
||||
|
||||
it('should inject css files when using the extract text plugin', function (done) {
|
||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||
var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/theme.js'),
|
||||
output: {
|
||||
|
|
@ -391,13 +391,13 @@ describe('HtmlWebpackPlugin', function() {
|
|||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({inject: true}),
|
||||
new ExtractTextPlugin("styles.css")
|
||||
new ExtractTextPlugin('styles.css')
|
||||
]
|
||||
}, ['<link href="styles.css"'], null, done);
|
||||
});
|
||||
|
||||
it('should allow to add cache hashes to with injected css assets', function (done) {
|
||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||
var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/theme.js'),
|
||||
output: {
|
||||
|
|
@ -411,12 +411,12 @@ describe('HtmlWebpackPlugin', function() {
|
|||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({hash: true, inject: true}),
|
||||
new ExtractTextPlugin("styles.css")
|
||||
new ExtractTextPlugin('styles.css')
|
||||
]
|
||||
}, ['<link href="styles.css?%hash%"'], null, done);
|
||||
});
|
||||
|
||||
it('prepends the webpack public path to script src', function(done) {
|
||||
it('prepends the webpack public path to script src', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -428,7 +428,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<script src="http://cdn.example.com/assets/index_bundle.js"'], null, done);
|
||||
});
|
||||
|
||||
it('handles subdirectories in the webpack output bundles', function(done) {
|
||||
it('handles subdirectories in the webpack output bundles', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -439,7 +439,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<script src="assets/index_bundle.js"'], null, done);
|
||||
});
|
||||
|
||||
it('handles subdirectories in the webpack output bundles along with a public path', function(done) {
|
||||
it('handles subdirectories in the webpack output bundles along with a public path', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -451,7 +451,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<script src="http://cdn.example.com/assets/index_bundle.js"'], null, done);
|
||||
});
|
||||
|
||||
it('allows you to configure the title of the generated HTML page', function(done) {
|
||||
it('allows you to configure the title of the generated HTML page', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -462,7 +462,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<title>My Cool App</title>'], null, done);
|
||||
});
|
||||
|
||||
it('allows you to configure the output filename', function(done) {
|
||||
it('allows you to configure the output filename', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -473,7 +473,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<script src="index_bundle.js"'], 'test.html', done);
|
||||
});
|
||||
|
||||
it('will try to use a relative name if the filename is in a subdirectory', function(done) {
|
||||
it('will try to use a relative name if the filename is in a subdirectory', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -484,7 +484,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<script src="../index_bundle.js"'], 'assets/test.html', done);
|
||||
});
|
||||
|
||||
it('will try to use a relative name if the filename and the script are in a subdirectory', function(done) {
|
||||
it('will try to use a relative name if the filename and the script are in a subdirectory', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -495,7 +495,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<script src="../../assets/index_bundle.js"'], 'assets/demo/test.html', done);
|
||||
});
|
||||
|
||||
it('allows you write multiple HTML files', function(done) {
|
||||
it('allows you write multiple HTML files', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
app: path.join(__dirname, 'fixtures/index.js')
|
||||
|
|
@ -515,16 +515,15 @@ describe('HtmlWebpackPlugin', function() {
|
|||
template: path.join(__dirname, 'fixtures/test.html')
|
||||
})
|
||||
]
|
||||
}, ['<script src="index_bundle.js"'], null, function(){
|
||||
}, ['<script src="index_bundle.js"'], null, function () {
|
||||
expect(fs.existsSync(path.join(OUTPUT_DIR, 'second-file.html'))).toBe(true);
|
||||
expect(fs.existsSync(path.join(OUTPUT_DIR, 'third-file.html'))).toBe(true);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should inject js css files even if the html file is incomplete', function (done) {
|
||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||
var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/theme.js'),
|
||||
output: {
|
||||
|
|
@ -538,12 +537,12 @@ describe('HtmlWebpackPlugin', function() {
|
|||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({template: path.join(__dirname, 'fixtures/empty_html.html')}),
|
||||
new ExtractTextPlugin("styles.css")
|
||||
new ExtractTextPlugin('styles.css')
|
||||
]
|
||||
}, ['<link href="styles.css"', '<script src="index_bundle.js"'], null, done);
|
||||
});
|
||||
|
||||
it('exposes the webpack configuration to templates', function(done) {
|
||||
it('exposes the webpack configuration to templates', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
app: path.join(__dirname, 'fixtures/index.js')
|
||||
|
|
@ -558,12 +557,12 @@ describe('HtmlWebpackPlugin', function() {
|
|||
['Public path is https://cdn.com'], null, done);
|
||||
});
|
||||
|
||||
it('fires the html-webpack-plugin-before-html-processing event', function(done) {
|
||||
it('fires the html-webpack-plugin-before-html-processing event', function (done) {
|
||||
var eventFired = false;
|
||||
var examplePlugin = {
|
||||
apply: function(compiler) {
|
||||
compiler.plugin('compilation', function(compilation) {
|
||||
compilation.plugin('html-webpack-plugin-before-html-processing', function(object, callback) {
|
||||
apply: function (compiler) {
|
||||
compiler.plugin('compilation', function (compilation) {
|
||||
compilation.plugin('html-webpack-plugin-before-html-processing', function (object, callback) {
|
||||
eventFired = true;
|
||||
callback();
|
||||
});
|
||||
|
|
@ -582,18 +581,18 @@ describe('HtmlWebpackPlugin', function() {
|
|||
new HtmlWebpackPlugin(),
|
||||
examplePlugin
|
||||
]
|
||||
},[], null, function() {
|
||||
}, [], null, function () {
|
||||
expect(eventFired).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('fires the html-webpack-plugin-after-html-processing event', function(done) {
|
||||
it('fires the html-webpack-plugin-after-html-processing event', function (done) {
|
||||
var eventFired = false;
|
||||
var examplePlugin = {
|
||||
apply: function(compiler) {
|
||||
compiler.plugin('compilation', function(compilation) {
|
||||
compilation.plugin('html-webpack-plugin-after-html-processing', function(object, callback) {
|
||||
apply: function (compiler) {
|
||||
compiler.plugin('compilation', function (compilation) {
|
||||
compilation.plugin('html-webpack-plugin-after-html-processing', function (object, callback) {
|
||||
eventFired = true;
|
||||
callback();
|
||||
});
|
||||
|
|
@ -612,18 +611,18 @@ describe('HtmlWebpackPlugin', function() {
|
|||
new HtmlWebpackPlugin(),
|
||||
examplePlugin
|
||||
]
|
||||
},[], null, function() {
|
||||
}, [], null, function () {
|
||||
expect(eventFired).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('fires the html-webpack-plugin-after-emit event', function(done) {
|
||||
it('fires the html-webpack-plugin-after-emit event', function (done) {
|
||||
var eventFired = false;
|
||||
var examplePlugin = {
|
||||
apply: function(compiler) {
|
||||
compiler.plugin('compilation', function(compilation) {
|
||||
compilation.plugin('html-webpack-plugin-after-emit', function(object, callback) {
|
||||
apply: function (compiler) {
|
||||
compiler.plugin('compilation', function (compilation) {
|
||||
compilation.plugin('html-webpack-plugin-after-emit', function (object, callback) {
|
||||
eventFired = true;
|
||||
callback();
|
||||
});
|
||||
|
|
@ -642,18 +641,18 @@ describe('HtmlWebpackPlugin', function() {
|
|||
new HtmlWebpackPlugin(),
|
||||
examplePlugin
|
||||
]
|
||||
},[], null, function() {
|
||||
}, [], null, function () {
|
||||
expect(eventFired).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('allows to modify the html during html-webpack-plugin-after-html-processing event', function(done) {
|
||||
it('allows to modify the html during html-webpack-plugin-after-html-processing event', function (done) {
|
||||
var eventFired = false;
|
||||
var examplePlugin = {
|
||||
apply: function(compiler) {
|
||||
compiler.plugin('compilation', function(compilation) {
|
||||
compilation.plugin('html-webpack-plugin-after-html-processing', function(object, callback) {
|
||||
apply: function (compiler) {
|
||||
compiler.plugin('compilation', function (compilation) {
|
||||
compilation.plugin('html-webpack-plugin-after-html-processing', function (object, callback) {
|
||||
eventFired = true;
|
||||
object.html += 'Injected by plugin';
|
||||
callback();
|
||||
|
|
@ -673,18 +672,18 @@ describe('HtmlWebpackPlugin', function() {
|
|||
new HtmlWebpackPlugin(),
|
||||
examplePlugin
|
||||
]
|
||||
},['Injected by plugin'], null, function() {
|
||||
}, ['Injected by plugin'], null, function () {
|
||||
expect(eventFired).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('allows to modify the html during html-webpack-plugin-before-html-processing event', function(done) {
|
||||
it('allows to modify the html during html-webpack-plugin-before-html-processing event', function (done) {
|
||||
var eventFired = false;
|
||||
var examplePlugin = {
|
||||
apply: function(compiler) {
|
||||
compiler.plugin('compilation', function(compilation) {
|
||||
compilation.plugin('html-webpack-plugin-before-html-processing', function(object, callback) {
|
||||
apply: function (compiler) {
|
||||
compiler.plugin('compilation', function (compilation) {
|
||||
compilation.plugin('html-webpack-plugin-before-html-processing', function (object, callback) {
|
||||
eventFired = true;
|
||||
object.assets.js.push('funky-script.js');
|
||||
object.html += 'Injected by plugin';
|
||||
|
|
@ -705,13 +704,13 @@ describe('HtmlWebpackPlugin', function() {
|
|||
new HtmlWebpackPlugin(),
|
||||
examplePlugin
|
||||
]
|
||||
},['Injected by plugin', '<script src="funky-script.js"'], null, function() {
|
||||
}, ['Injected by plugin', '<script src="funky-script.js"'], null, function () {
|
||||
expect(eventFired).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('works with commons chunk plugin', function(done) {
|
||||
it('works with commons chunk plugin', function (done) {
|
||||
testHtmlPlugin({
|
||||
debug: true,
|
||||
verbose: true,
|
||||
|
|
@ -726,7 +725,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
plugins: [
|
||||
new CommonsChunkPlugin({
|
||||
name: 'common',
|
||||
filename: "common_bundle.js",
|
||||
filename: 'common_bundle.js'
|
||||
}),
|
||||
new HtmlWebpackPlugin()
|
||||
]
|
||||
|
|
@ -735,7 +734,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
/<script src="common_bundle.js"[\s\S]*<script src="index_bundle.js">/], null, done);
|
||||
});
|
||||
|
||||
it('adds a favicon', function(done) {
|
||||
it('adds a favicon', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -750,7 +749,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, [/<link rel="shortcut icon" href="[^"]+\.ico">/], null, done);
|
||||
});
|
||||
|
||||
it('adds a favicon with inject enabled', function(done) {
|
||||
it('adds a favicon with inject enabled', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -766,7 +765,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, [/<link rel="shortcut icon" href="[^"]+\.ico">/], null, done);
|
||||
});
|
||||
|
||||
it('shows an error if the favicon could not be load', function(done) {
|
||||
it('shows an error if the favicon could not be load', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -782,7 +781,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['Error: HtmlWebpackPlugin: could not load file'], null, done, true);
|
||||
});
|
||||
|
||||
it('adds a manifest', function(done) {
|
||||
it('adds a manifest', function (done) {
|
||||
var AppCachePlugin = require('appcache-webpack-plugin');
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
|
|
@ -797,7 +796,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<html manifest="manifest.appcache">'], null, done);
|
||||
});
|
||||
|
||||
it('does not add a manifest if already present', function(done) {
|
||||
it('does not add a manifest if already present', function (done) {
|
||||
var AppCachePlugin = require('appcache-webpack-plugin');
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
|
|
@ -808,13 +807,13 @@ describe('HtmlWebpackPlugin', function() {
|
|||
plugins: [
|
||||
new AppCachePlugin({settings: ['prefer-online']}),
|
||||
new HtmlWebpackPlugin({
|
||||
template: path.join(__dirname, 'fixtures/plain.html'),
|
||||
template: path.join(__dirname, 'fixtures/plain.html')
|
||||
})
|
||||
]
|
||||
}, ['<html lang="en" manifest="foo.appcache">'], null, done);
|
||||
});
|
||||
|
||||
it('works with webpack bannerplugin', function(done) {
|
||||
it('works with webpack bannerplugin', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -828,7 +827,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<html'], null, done);
|
||||
});
|
||||
|
||||
it('shows an error when a template fails to load', function(done) {
|
||||
it('shows an error when a template fails to load', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
|
|
@ -843,7 +842,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ["Child compilation failed:\n Entry module not found: Error: Cannot resolve 'file' or 'directory'"], null, done, true);
|
||||
});
|
||||
|
||||
it('should short the chunks', function(done) {
|
||||
it('should short the chunks', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
util: path.join(__dirname, 'fixtures/util.js'),
|
||||
|
|
@ -856,7 +855,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
plugins: [
|
||||
new CommonsChunkPlugin({
|
||||
name: 'common',
|
||||
filename: "common_bundle.js",
|
||||
filename: 'common_bundle.js'
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
chunksSortMode: 'auto'
|
||||
|
|
@ -866,7 +865,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
/<script src="common_bundle.js">.+<script src="util_bundle.js">.+<script src="index_bundle.js">/], null, done);
|
||||
});
|
||||
|
||||
it('should short the chunks with custom (alphabetical) order', function(done) {
|
||||
it('should short the chunks with custom (alphabetical) order', function (done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
b: path.join(__dirname, 'fixtures/index.js'),
|
||||
|
|
@ -879,14 +878,17 @@ describe('HtmlWebpackPlugin', function() {
|
|||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
chunksSortMode: function(a, b) {
|
||||
if(a.name < b.name) {return 1;}
|
||||
if(a.name > b.name) {return -1;}
|
||||
chunksSortMode: function (a, b) {
|
||||
if (a.name < b.name) {
|
||||
return 1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
})
|
||||
]
|
||||
}, [/<script src="a_bundle.js">.+<script src="b_bundle.js">.+<script src="c_bundle.js">/], null, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
'use strict';
|
||||
module.exports = "async";
|
||||
module.exports = 'async';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = "common";
|
||||
module.exports = 'common';
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
require('./common');
|
||||
|
||||
require.ensure([], function() {
|
||||
require.ensure([], function () {
|
||||
require('./async');
|
||||
});
|
||||
|
||||
document.body.innerHTML = document.body.innerHTML + "<p>index.js</p>";
|
||||
document.body.innerHTML = document.body.innerHTML + '<p>index.js</p>';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
require('./main.css');
|
||||
require('./index.js');
|
||||
require('./index.js');
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
require('./common');
|
||||
document.body.innerHTML = document.body.innerHTML + "<p>util.js</p>";
|
||||
document.body.innerHTML = document.body.innerHTML + '<p>util.js</p>';
|
||||
|
|
|
|||
Loading…
Reference in New Issue