-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making template compatible with html-webpack-plugin
injection
#83
Open
vladimyr
wants to merge
21
commits into
jaketrent:master
Choose a base branch
from
vladimyr:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e1ae067
chore: add commitizen to dev dependencies
vladimyr 8343044
chore: fill license placeholders
vladimyr 5051dc2
chore: add editorconfig
vladimyr 1056570
chore: update gitignore
vladimyr 14e2ec6
chore: migrate from npmignore to package.json files
vladimyr 74c201c
refactor!: refactor ejs template
vladimyr 8217f6d
tests: add tests
zcuric cd201a4
refactor: use template strings for link/script attributes generation
vladimyr 9b210c2
tests: refactor test suite
vladimyr 2fe47f5
improvement: updating example
vladimyr b2baf5d
chore: test suite tweaks, style tweaks
vladimyr 1f7adb2
chore: update eslint config
vladimyr 4bdd300
improvement: generate xhtml compliant link tags
vladimyr 8e2e2ad
chore: update outdated browser page url
vladimyr c95a05c
fix: move eslint to devDependencies
zcuric d29191d
chore: upgrade dependencies :package:
vladimyr aced356
chore: sort `package.json` fields
vladimyr cdc7b44
chore: move tests around
vladimyr 557c50d
chore: update `.gitignore`
vladimyr 26e09ee
chore: address npm audit warnings
vladimyr 714a64c
chore(examples): upgrade dependencies, tweak webpack config
vladimyr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 2 | ||
indent_style = space | ||
end_of_line = lf | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
extends: 'semistandard' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
.vscode | ||
.idea | ||
npm-debug.log | ||
dist |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) <year> <copyright holders> | ||
Copyright (c) 2015 Jake Trent <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
"presets": ["@babel/preset-env"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
const app = document.getElementById('app') | ||
const app = document.getElementById('app'); | ||
|
||
app.innerHTML = | ||
'This is an app in the template.<br /><br />' + | ||
'Some variables from your webpack.config.js:<br/>' + | ||
'title: ' + document.title + '<br />' + | ||
'window.env.apiHost: ' + window.env.apiHost | ||
app.innerHTML = ` | ||
This is an app in the template.<br><br> | ||
Some variables from your <strong>webpack.config.js</strong>:<br> | ||
<pre> | ||
title: ${document.title} | ||
window.env.apiHost: ${window.env.apiHost} | ||
</pre> | ||
`; | ||
|
||
document.documentElement.style.fontFamily = 'Roboto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,98 @@ | ||
<% var item, key %><% | ||
htmlWebpackPlugin.options.appMountIds = htmlWebpackPlugin.options.appMountIds || [] %><% | ||
htmlWebpackPlugin.options.lang = htmlWebpackPlugin.options.lang || "en" %><% | ||
htmlWebpackPlugin.options.links = htmlWebpackPlugin.options.links || [] %><% | ||
htmlWebpackPlugin.options.meta = htmlWebpackPlugin.options.meta || [] %><% | ||
htmlWebpackPlugin.options.scripts = htmlWebpackPlugin.options.scripts || [] | ||
%><!DOCTYPE html> | ||
<html lang="<%= htmlWebpackPlugin.options.lang %>"<% if (htmlWebpackPlugin.files.manifest) { %> manifest="<%= htmlWebpackPlugin.files.manifest %>"<% } %>> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta content="ie=edge" http-equiv="x-ua-compatible"><% | ||
|
||
if (htmlWebpackPlugin.options.baseHref) { %> | ||
<base href="<%= htmlWebpackPlugin.options.baseHref %>"><% | ||
} %><% | ||
|
||
if (Array.isArray(htmlWebpackPlugin.options.meta)) { %><% | ||
for (item of htmlWebpackPlugin.options.meta) { %> | ||
<meta<% for (key in item) { %> <%= key %>="<%= item[key] %>"<% } %>><% | ||
} %><% | ||
} %><% | ||
|
||
%> | ||
<title><%= htmlWebpackPlugin.options.title %></title><% | ||
|
||
if (htmlWebpackPlugin.files.favicon) { %> | ||
<link href="<%= htmlWebpackPlugin.files.favicon %>" rel="shortcut icon" /><% | ||
} %><% | ||
<% | ||
const { options } = htmlWebpackPlugin; | ||
|
||
const xhtml = options.xhtml; | ||
const lang = options.lang || 'en'; | ||
const title = options.title; | ||
const description = options.description; | ||
const mobile = options.mobile; | ||
const headHtmlSnippet = options.headHtmlSnippet; | ||
const unsupportedBrowser = options.unsupportedBrowser; | ||
const bodyHtmlSnippet = options.bodyHtmlSnippet; | ||
const appMountHtmlSnippet = options.appMountHtmlSnippet; | ||
const appMountIds = options.appMountIds || []; | ||
const window = options.window; | ||
const googleAnalytics = options.googleAnalytics; | ||
|
||
const isString = arg => typeof arg === 'string'; | ||
const toAttributes = obj => { | ||
return Object.entries(obj) | ||
.map(([key, value]) => ` ${key}="${value}"`) | ||
.join(''); | ||
} | ||
|
||
let appMountId = options.appMountId; | ||
if (appMountIds.length <= 0) appMountId = appMountId || 'app'; | ||
|
||
const links = (options.links || []).map(link => { | ||
if (isString(link)) return { href: link, rel: 'stylesheet' }; | ||
return link; | ||
}); | ||
const scripts = (options.scripts || []).map(script => { | ||
if (isString(script)) return { src: script, type: 'text/javascript' }; | ||
return script; | ||
}); | ||
|
||
if (htmlWebpackPlugin.options.mobile) { %> | ||
<meta content="width=device-width, initial-scale=1" name="viewport"><% | ||
} %><% | ||
|
||
for (item of htmlWebpackPlugin.options.links) { %><% | ||
if (typeof item === 'string' || item instanceof String) { item = { href: item, rel: 'stylesheet' } } %> | ||
<link<% for (key in item) { %> <%= key %>="<%= item[key] %>"<% } %> /><% | ||
} %><% | ||
|
||
for (key in htmlWebpackPlugin.files.css) { %><% | ||
if (htmlWebpackPlugin.files.cssIntegrity) { %> | ||
<link | ||
href="<%= htmlWebpackPlugin.files.css[key] %>" | ||
rel="stylesheet" | ||
integrity="<%= htmlWebpackPlugin.files.cssIntegrity[key] %>" | ||
crossorigin="<%= webpackConfig.output.crossOriginLoading %>" /><% | ||
} else { %> | ||
<link href="<%= htmlWebpackPlugin.files.css[key] %>" rel="stylesheet" /><% | ||
} %><% | ||
} %><% | ||
if (htmlWebpackPlugin.options.headHtmlSnippet) { %> | ||
<%= htmlWebpackPlugin.options.headHtmlSnippet %><% | ||
%><!DOCTYPE html> | ||
<html lang="<%= lang %>"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta content="ie=edge" http-equiv="x-ua-compatible"> | ||
<title><%= title %></title><% | ||
if (description) { %> | ||
<meta name="description" content="<%= description %>"><% | ||
} %><% | ||
if (mobile) { %> | ||
<meta content="width=device-width, initial-scale=1" name="viewport"><% | ||
} %><% | ||
for (let link of links) { %> | ||
<link<%= toAttributes(link) %><% if (xhtml) { %>/<% } %>><% | ||
} %><% | ||
if (headHtmlSnippet) { %> | ||
<%= headHtmlSnippet %><% | ||
} %> | ||
</head> | ||
<body> | ||
<noscript> | ||
We're sorry but <%= title %> doesn't work properly without JavaScript enabled. Please enable it to continue. | ||
</noscript><% | ||
if (unsupportedBrowser) { %> | ||
<style>.unsupported-browser { display: none; }</style> | ||
<div class="unsupported-browser"> | ||
Sorry, your browser is not supported. Please upgrade to the latest version or switch your browser to use this | ||
site. See <a href="https://bestvpn.org/outdatedbrowser/" rel="noopener noreferrer">outdatedbrowser.com</a> for options. | ||
</div><% | ||
} %><% | ||
if (bodyHtmlSnippet) { %> | ||
<%= bodyHtmlSnippet %><% | ||
} %><% | ||
if (appMountId) { %> | ||
<div id="<%= appMountId %>"><% if (appMountHtmlSnippet) { %><%= appMountHtmlSnippet %><% } %></div><% | ||
} %><% | ||
for (let appMountId of appMountIds) { %> | ||
<div id="<%= appMountId %>"></div><% | ||
} %><% | ||
if (window) { %> | ||
<script type="text/javascript"><% | ||
for (let [key, value] of Object.entries(window)) { %> | ||
window['<%= key %>'] = <%= JSON.stringify(value) %>;<% | ||
} %> | ||
</head> | ||
<body><% | ||
if (htmlWebpackPlugin.options.unsupportedBrowser) { %> | ||
<style>.unsupported-browser { display: none; }</style> | ||
<div class="unsupported-browser"> | ||
Sorry, your browser is not supported. Please upgrade to the latest version or switch your browser to use this | ||
site. See <a href="http://outdatedbrowser.com/">outdatedbrowser.com</a> for options. | ||
</div><% | ||
} %><% | ||
|
||
if (htmlWebpackPlugin.options.bodyHtmlSnippet) { %> | ||
<%= htmlWebpackPlugin.options.bodyHtmlSnippet %><% | ||
} %><% | ||
|
||
if (htmlWebpackPlugin.options.appMountId) { %> | ||
<div id="<%= htmlWebpackPlugin.options.appMountId %>"><% | ||
if (htmlWebpackPlugin.options.appMountHtmlSnippet) { %> | ||
<%= htmlWebpackPlugin.options.appMountHtmlSnippet %><% | ||
} %> | ||
</div><% | ||
} %><% | ||
|
||
for (item of htmlWebpackPlugin.options.appMountIds) { %> | ||
<div id="<%= item %>"></div><% | ||
} %><% | ||
|
||
if (htmlWebpackPlugin.options.window) { %> | ||
<script type="text/javascript"><% | ||
for (key in htmlWebpackPlugin.options.window) { %> | ||
window['<%= key %>'] = <%= JSON.stringify(htmlWebpackPlugin.options.window[key]) %>;<% | ||
} %> | ||
</script><% | ||
} %><% | ||
|
||
if (htmlWebpackPlugin.options.inlineManifestWebpackName) { %> | ||
<%= htmlWebpackPlugin.files[htmlWebpackPlugin.options.inlineManifestWebpackName] %><% | ||
} %><% | ||
|
||
for (item of htmlWebpackPlugin.options.scripts) { %><% | ||
if (typeof item === 'string' || item instanceof String) { item = { src: item, type: 'text/javascript' } } %> | ||
<script<% for (key in item) { %> <%= key %>="<%= item[key] %>"<% } %>></script><% | ||
} %><% | ||
|
||
for (key in htmlWebpackPlugin.files.chunks) { %><% | ||
if (htmlWebpackPlugin.files.jsIntegrity) { %> | ||
<script | ||
src="<%= htmlWebpackPlugin.files.chunks[key].entry %>" | ||
type="text/javascript" | ||
integrity="<%= htmlWebpackPlugin.files.jsIntegrity[htmlWebpackPlugin.files.js.indexOf(htmlWebpackPlugin.files.chunks[key].entry)] %>" | ||
crossorigin="<%= webpackConfig.output.crossOriginLoading %>"></script><% | ||
} else { %> | ||
<script src="<%= htmlWebpackPlugin.files.chunks[key].entry %>" type="text/javascript"></script><% | ||
} %><% | ||
} %><% | ||
|
||
if (htmlWebpackPlugin.options.devServer) { %> | ||
<script src="<%= htmlWebpackPlugin.options.devServer %>/webpack-dev-server.js" type="text/javascript"></script><% | ||
} %><% | ||
|
||
if (htmlWebpackPlugin.options.googleAnalytics) { %> | ||
<script type="text/javascript"> | ||
window.GoogleAnalyticsObject='ga';window.ga=function(){ga.q.push(arguments)};ga.q=[];ga.l=+new Date;<% | ||
|
||
if (htmlWebpackPlugin.options.googleAnalytics.trackingId) { %> | ||
ga('create','<%= htmlWebpackPlugin.options.googleAnalytics.trackingId %>','auto');<% | ||
} else { throw new Error("html-webpack-template requires googleAnalytics.trackingId config"); } %><% | ||
|
||
if (htmlWebpackPlugin.options.googleAnalytics.pageViewOnLoad) { %> | ||
ga('send','pageview')<% | ||
} %> | ||
</script> | ||
<script async defer src="https://www.google-analytics.com/analytics.js" type="text/javascript"></script><% | ||
</script><% | ||
} %><% | ||
for (let script of scripts) { %> | ||
<script<%= toAttributes(script) %>></script><% | ||
} %><% | ||
if (googleAnalytics) { %> | ||
<script type="text/javascript"> | ||
window.GoogleAnalyticsObject='ga';window.ga=function(){ga.q.push(arguments);};ga.q=[];ga.l=+new Date;<% | ||
if (googleAnalytics.trackingId) { %> | ||
ga('create','<%= googleAnalytics.trackingId %>','auto');<% | ||
} else { throw new Error('html-webpack-template requires googleAnalytics.trackingId config'); } %><% | ||
if (googleAnalytics.pageViewOnLoad) { %> | ||
ga('send','pageview');<% | ||
} %> | ||
</body> | ||
</script> | ||
<script async defer src="https://www.google-analytics.com/analytics.js" type="text/javascript"></script><% | ||
} %> | ||
</body> | ||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to keep the ability to add meta tags as an array -- a user can add as many of the unanticipated kind of meta tags as they want. This package has drifted this direction as more and more people have wanted it to do more things: Just allow general setting of html via json.