Skip to content

Commit 3b892d9

Browse files
committed
fix: fix doc-scripts.header/footer.html is not work
1 parent 93f2c0a commit 3b892d9

File tree

10 files changed

+70
-63
lines changed

10 files changed

+70
-63
lines changed

examples/doc-scripts.header.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
alert('custom')
3+
</script>

lib/assets/template.ejs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta content="text/html; charset=utf-8" http-equiv="Content-type" />
5-
<title><%= htmlWebpackPlugin.options.title %></title>
5+
<title><%= title %></title>
66
<base target="_parent">
77
<script>
88
var process = {
@@ -18,10 +18,7 @@
1818
}
1919
}
2020
</script>
21-
<% if (htmlWebpackPlugin.options.hot) { %>
22-
<script src="http://localhost:<%= htmlWebpackPlugin.options.port %>/webpack-dev-server.js"></script>
23-
<% } %>
24-
<%= htmlWebpackPlugin.options.header %>
21+
<%= header %>
2522
<style>
2623
.loading-svg {
2724
position: absolute;
@@ -62,14 +59,14 @@
6259
},1000)
6360
</script>
6461
<script
65-
src="https://unpkg.com/react@16/umd/react.<%= htmlWebpackPlugin.options.development ? "development" : "production.min" %>.js"
62+
src="https://unpkg.com/react@16/umd/react.<%= development ? "development" : "production.min" %>.js"
6663
></script>
6764
<script
68-
src="https://unpkg.com/react-dom@16/umd/react-dom.<%= htmlWebpackPlugin.options.development ? "development" : "production.min" %>.js"
65+
src="https://unpkg.com/react-dom@16/umd/react-dom.<%= development ? "development" : "production.min" %>.js"
6966
></script>
7067
<script
71-
src="https://unpkg.com/react-is@16/umd/react-is.<%= htmlWebpackPlugin.options.development ? "development" : "production.min" %>.js"
68+
src="https://unpkg.com/react-is@16/umd/react-is.<%= development ? "development" : "production.min" %>.js"
7269
></script>
73-
<%= htmlWebpackPlugin.options.footer %>
70+
<%= footer %>
7471
</body>
7572
</html>

lib/webpack/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ module.exports = _async(function (mode, options, webpackConfig) {
7272

7373
var config = require("./" + mode);
7474

75-
var userConfigPath = path.resolve(cwd, './doc-scripts.config.js');
76-
var headerPath = path.resolve(cwd, './doc-scripts.header.html');
77-
var footerPath = path.resolve(cwd, './doc-scripts.footer.html');
75+
var userConfigPath = path.resolve(options.input, './doc-scripts.config.js');
76+
var headerPath = path.resolve(options.input, './doc-scripts.header.html');
77+
var footerPath = path.resolve(options.input, './doc-scripts.footer.html');
7878
return _continue(_catch(function () {
7979
var userConfigContents = webpackConfig;
8080
return _continue(_catch(function () {

lib/webpack/development.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,27 @@ module.exports = function (options) {
4242
}
4343
}));
4444
config.plugins.push(new HtmlWebpackPlugin({
45-
title: title ? title : pkg.name + "@" + pkg.version,
4645
filename: 'index.html',
4746
template: path.resolve(__dirname, '../assets/template.ejs'),
4847
inject: 'body',
49-
port: port,
50-
hot: true,
5148
chunks: ['index'],
52-
development: true,
53-
header: header,
54-
footer: footer
49+
templateParameters: {
50+
title: title ? title : pkg.name + "@" + pkg.version,
51+
development: true,
52+
header: header,
53+
footer: footer
54+
}
5555
}), new HtmlWebpackPlugin({
56-
title: title ? title : pkg.name + "@" + pkg.version,
5756
filename: 'iframe.html',
5857
template: path.resolve(__dirname, '../assets/template.ejs'),
5958
inject: 'body',
60-
port: port,
61-
hot: true,
6259
chunks: ['iframe'],
63-
development: true,
64-
header: header,
65-
footer: footer
60+
templateParameters: {
61+
title: title ? title : pkg.name + "@" + pkg.version,
62+
development: true,
63+
header: header,
64+
footer: footer
65+
}
6666
}));
6767
config.entry.index.push(require.resolve('webpack/hot/dev-server'), require.resolve('webpack-dev-server/client') + "?http://localhost:" + port);
6868
config.entry.iframe.push(require.resolve('webpack/hot/dev-server'), require.resolve('webpack-dev-server/client') + "?http://localhost:" + port);

lib/webpack/production.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,28 @@ module.exports = function (options) {
2222

2323
var config = baseConfig(options);
2424
config.plugins.push(new HtmlWebpackPlugin({
25-
title: title ? title : pkg.name + "@" + pkg.version,
2625
filename: 'index.html',
2726
template: path.resolve(__dirname, '../assets/template.ejs'),
2827
inject: 'body',
2928
chunks: ['index'],
30-
header: header,
31-
footer: footer,
32-
hot: false
29+
templateParameters: {
30+
title: title ? title : pkg.name + "@" + pkg.version,
31+
development: true,
32+
header: header,
33+
footer: footer
34+
}
3335
}), new HtmlWebpackPlugin({
3436
title: title ? title : pkg.name + "@" + pkg.version,
3537
filename: 'iframe.html',
3638
template: path.resolve(__dirname, '../assets/template.ejs'),
3739
inject: 'body',
3840
chunks: ['iframe'],
39-
header: header,
40-
footer: footer,
41-
hot: false
41+
templateParameters: {
42+
title: title ? title : pkg.name + "@" + pkg.version,
43+
development: true,
44+
header: header,
45+
footer: footer
46+
}
4247
}));
4348
return (0, _extends2["default"])({}, config, {
4449
mode: 'production'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "doc-scripts",
3-
"version": "1.7.24",
3+
"version": "1.7.26",
44
"description": "react demo server",
55
"main": "lib",
66
"scripts": {

src/assets/template.ejs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta content="text/html; charset=utf-8" http-equiv="Content-type" />
5-
<title><%= htmlWebpackPlugin.options.title %></title>
5+
<title><%= title %></title>
66
<base target="_parent">
77
<script>
88
var process = {
@@ -18,10 +18,7 @@
1818
}
1919
}
2020
</script>
21-
<% if (htmlWebpackPlugin.options.hot) { %>
22-
<script src="http://localhost:<%= htmlWebpackPlugin.options.port %>/webpack-dev-server.js"></script>
23-
<% } %>
24-
<%= htmlWebpackPlugin.options.header %>
21+
<%= header %>
2522
<style>
2623
.loading-svg {
2724
position: absolute;
@@ -62,14 +59,14 @@
6259
},1000)
6360
</script>
6461
<script
65-
src="https://unpkg.com/react@16/umd/react.<%= htmlWebpackPlugin.options.development ? "development" : "production.min" %>.js"
62+
src="https://unpkg.com/react@16/umd/react.<%= development ? "development" : "production.min" %>.js"
6663
></script>
6764
<script
68-
src="https://unpkg.com/react-dom@16/umd/react-dom.<%= htmlWebpackPlugin.options.development ? "development" : "production.min" %>.js"
65+
src="https://unpkg.com/react-dom@16/umd/react-dom.<%= development ? "development" : "production.min" %>.js"
6966
></script>
7067
<script
71-
src="https://unpkg.com/react-is@16/umd/react-is.<%= htmlWebpackPlugin.options.development ? "development" : "production.min" %>.js"
68+
src="https://unpkg.com/react-is@16/umd/react-is.<%= development ? "development" : "production.min" %>.js"
7269
></script>
73-
<%= htmlWebpackPlugin.options.footer %>
70+
<%= footer %>
7471
</body>
7572
</html>

src/webpack/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const cwd = process.cwd()
66

77
module.exports = async function(mode, options = {}, webpackConfig) {
88
const config = require(`./${mode}`)
9-
const userConfigPath = path.resolve(cwd, './doc-scripts.config.js')
10-
const headerPath = path.resolve(cwd, './doc-scripts.header.html')
11-
const footerPath = path.resolve(cwd, './doc-scripts.footer.html')
9+
const userConfigPath = path.resolve(options.input, './doc-scripts.config.js')
10+
const headerPath = path.resolve(options.input, './doc-scripts.header.html')
11+
const footerPath = path.resolve(options.input, './doc-scripts.footer.html')
1212
try {
1313
let userConfigContents = webpackConfig
1414
try {

src/webpack/development.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,28 @@ module.exports = options => {
3131
)
3232
config.plugins.push(
3333
new HtmlWebpackPlugin({
34-
title: title ? title : `${pkg.name}@${pkg.version}`,
3534
filename: 'index.html',
3635
template: path.resolve(__dirname, '../assets/template.ejs'),
3736
inject: 'body',
38-
port: port,
39-
hot: true,
4037
chunks:['index'],
41-
development: true,
42-
header,
43-
footer
38+
templateParameters:{
39+
title: title ? title : `${pkg.name}@${pkg.version}`,
40+
development: true,
41+
header,
42+
footer
43+
}
4444
}),
4545
new HtmlWebpackPlugin({
46-
title: title ? title : `${pkg.name}@${pkg.version}`,
4746
filename: 'iframe.html',
4847
template: path.resolve(__dirname, '../assets/template.ejs'),
4948
inject: 'body',
50-
port: port,
51-
hot: true,
5249
chunks:['iframe'],
53-
development: true,
54-
header,
55-
footer
50+
templateParameters:{
51+
title: title ? title : `${pkg.name}@${pkg.version}`,
52+
development: true,
53+
header,
54+
footer
55+
}
5656
})
5757
)
5858

src/webpack/production.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,29 @@ module.exports = (options) => {
99
const config = baseConfig(options)
1010
config.plugins.push(
1111
new HtmlWebpackPlugin({
12-
title: title ? title : `${pkg.name}@${pkg.version}`,
1312
filename: 'index.html',
1413
template: path.resolve(__dirname, '../assets/template.ejs'),
1514
inject: 'body',
1615
chunks:['index'],
17-
header,
18-
footer,
19-
hot: false
16+
templateParameters:{
17+
title: title ? title : `${pkg.name}@${pkg.version}`,
18+
development: true,
19+
header,
20+
footer
21+
}
2022
}),
2123
new HtmlWebpackPlugin({
2224
title: title ? title : `${pkg.name}@${pkg.version}`,
2325
filename: 'iframe.html',
2426
template: path.resolve(__dirname, '../assets/template.ejs'),
2527
inject: 'body',
2628
chunks:['iframe'],
27-
header,
28-
footer,
29-
hot: false
29+
templateParameters:{
30+
title: title ? title : `${pkg.name}@${pkg.version}`,
31+
development: true,
32+
header,
33+
footer
34+
}
3035
})
3136
)
3237
return {

0 commit comments

Comments
 (0)