Generated HTML loads multiple entry points
This commit is contained in:
parent
d9d3b23c56
commit
7d27822455
|
|
@ -5,6 +5,8 @@
|
|||
<title>React Starter</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="{%=o.htmlWebpackPlugin.assets.main%}"></script>
|
||||
{% for (var chunk in o.htmlWebpackPlugin.assets) { %}
|
||||
<script src="{%=o.htmlWebpackPlugin.assets[chunk]%}"></script>
|
||||
{% } %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
19
index.js
19
index.js
|
|
@ -5,15 +5,6 @@ var tmpl = require('blueimp-tmpl').tmpl;
|
|||
function HtmlWebpackPlugin() {
|
||||
}
|
||||
|
||||
HtmlWebpackPlugin.prototype.htmlWebpackPluginJson = function(webpackStatsJson) {
|
||||
json = {};
|
||||
json.assets = {};
|
||||
for (var chunk in webpackStatsJson.assetsByChunkName) {
|
||||
json.assets[chunk] = webpackStatsJson.assetsByChunkName[chunk];
|
||||
}
|
||||
return json;
|
||||
};
|
||||
|
||||
HtmlWebpackPlugin.prototype.apply = function(compiler) {
|
||||
var self = this;
|
||||
compiler.plugin('done', function(stats) {
|
||||
|
|
@ -27,4 +18,14 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {
|
|||
});
|
||||
};
|
||||
|
||||
HtmlWebpackPlugin.prototype.htmlWebpackPluginJson = function(webpackStatsJson) {
|
||||
var json = {};
|
||||
json.assets = {};
|
||||
for (var chunk in webpackStatsJson.assetsByChunkName) {
|
||||
json.assets[chunk] = webpackStatsJson.assetsByChunkName[chunk];
|
||||
}
|
||||
|
||||
return json;
|
||||
};
|
||||
|
||||
module.exports = HtmlWebpackPlugin;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
"devDependencies": {
|
||||
"jasmine-node": "^1.14.5",
|
||||
"jshint": "^2.5.2",
|
||||
"rimraf": "^2.2.8",
|
||||
"webpack": "^1.3.3-beta1"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,51 @@
|
|||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var webpack = require('webpack');
|
||||
|
||||
var rm_rf = require('rimraf');
|
||||
var HtmlWebpackPlugin = require('../index.js');
|
||||
|
||||
describe('HtmlWebpackPlugin', function() {
|
||||
it('generates a default index.html file for a single entry point', function(done) {
|
||||
var outputDir = path.join(__dirname, '..', 'dist');
|
||||
var outputHtmlFile = path.join(outputDir, 'index.html');
|
||||
var OUTPUT_DIR = path.join(__dirname, '..', 'dist');
|
||||
|
||||
webpack({
|
||||
function testHtmlPlugin(webpackConfig, expectedResults, done) {
|
||||
var outputHtmlFile = path.join(OUTPUT_DIR, 'index.html');
|
||||
webpackConfig.plugins = [new HtmlWebpackPlugin()];
|
||||
webpack(webpackConfig, function(err, stats) {
|
||||
expect(err).toBeFalsy();
|
||||
expect(stats.hasErrors()).toBe(false);
|
||||
var htmlContent = fs.readFileSync(outputHtmlFile).toString();
|
||||
for (var i = 0; i < expectedResults.length; i++) {
|
||||
expect(htmlContent).toContain(expectedResults[i]);
|
||||
}
|
||||
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) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures', 'index.js'),
|
||||
output: {
|
||||
path: outputDir,
|
||||
path: OUTPUT_DIR,
|
||||
filename: 'index_bundle.js'
|
||||
}
|
||||
}, ['<script src="index_bundle.js"'], done);
|
||||
|
||||
});
|
||||
|
||||
it('generates a default index.html file with multiple entry points', function(done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
util: path.join(__dirname, 'fixtures', 'util.js'),
|
||||
app: path.join(__dirname, 'fixtures', 'index.js')
|
||||
},
|
||||
plugins: [new HtmlWebpackPlugin()]
|
||||
}, function(err, stats) {
|
||||
expect(err).toBeFalsy();
|
||||
expect(stats.hasErrors()).toBe(false);
|
||||
expect(fs.readFileSync(outputHtmlFile).toString()).toContain('<script src="index_bundle.js"');
|
||||
done();
|
||||
});
|
||||
output: {
|
||||
path: OUTPUT_DIR,
|
||||
filename: '[name]_bundle.js'
|
||||
}
|
||||
}, ['<script src="util_bundle.js"', '<script src="app_bundle.js"'], done);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
document.body.textContent = "Hello world";
|
||||
document.body.textContent = helloText();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
function helloText() {
|
||||
return "Hello world";
|
||||
}
|
||||
Loading…
Reference in New Issue