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
<!DOCTYPE html> | |
<html lang="en" dir="ltr"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Handling script loading errors with HtmlWebpackPlugin</title> | |
</head> | |
<body> | |
<h1 id="content"></h1> | |
<script> |
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
<script> | |
(function(){ | |
function showErrorPage() { | |
// Doesn't matter for now | |
} | |
window.addEventListener('DOMContentLoaded', function() { | |
var appScript = document.querySelector('script[src^="bundle"]'); | |
appScript.addEventListener('error', showErrorPage); | |
}); |
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
plugins: [ | |
new HtmlWebpackPlugin({ | |
inject: 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
<script> | |
(function() { | |
function showErrorMessage() { | |
alert('Oops, something went wrong! Please reload the page.'); | |
} | |
// Paths of all bundles | |
var bundlesSrcs = <%= JSON.stringify(htmlWebpackPlugin.files.js) %>; | |
for(var i=0; i < bundlesSrcs.length; i++) { | |
// Create script tag & configure it |
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
module: { | |
rules: [ | |
{ | |
test: /\.(png|jpe?g|gif)$/i, | |
loader: 'file-loader' | |
} | |
] | |
} |
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
<!DOCTYPE html> | |
<html lang="en" dir="ltr"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Handling script loading errors with HtmlWebpackPlugin</title> | |
<style> | |
html, body, h1 { | |
padding: 0; | |
margin: 0; |
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
const App = () => { | |
const [total, setTotal] = useState(0); | |
const incrementTotal = () => setTotal(currentTotal => currentTotal + 1); | |
return ( | |
<div className="App"> | |
<div> | |
<h4>Total Clicks: {total}</h4> | |
</div> | |
<div className="CountersContainer"> |
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
const App = () => { | |
const [total, setTotal] = useState(0); | |
const incrementTotal = () => setTotal((currentTotal) => currentTotal + 1); | |
const Description = () => ( | |
<p> | |
I like coding counters! | |
Sum of all counters is now {total} | |
</p> | |
); |
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
const App = () => { | |
const [total, setTotal] = useState(0); | |
const incrementTotal = () => setTotal((currentTotal) => currentTotal + 1); | |
const Description = () => ( | |
<p>I like coding counters! Sum of all counters is now {total}</p> | |
); | |
const CounterWithWeekday = (props) => { | |
let today; | |
switch (new Date().getDay()) { | |
case 0: |
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
// A magical structure that repeats whatever | |
// we need to repeat an arbitrary number of times | |
// ⬇️ | |
for (let i = 0; i <= 10; i++) { | |
console.log(i); // ⬅️ procedure to repeat | |
} |
OlderNewer