mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 21:02:33 +03:00
Use template for html file that loads service worker file.
This commit is contained in:
parent
6af5a1ca11
commit
e2c7cbad73
@ -9,7 +9,7 @@ const PrerenderSPAPlugin = require("prerender-spa-plugin");
|
|||||||
|
|
||||||
module.exports = { start, run };
|
module.exports = { start, run };
|
||||||
function start({ routes }) {
|
function start({ routes }) {
|
||||||
const compiler = webpack(webpackOptions(routes));
|
const compiler = webpack(webpackOptions(true, routes));
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(middleware(compiler, { publicPath: "/" }));
|
app.use(middleware(compiler, { publicPath: "/" }));
|
||||||
@ -36,17 +36,22 @@ function start({ routes }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function run({ routes }) {
|
function run({ routes }) {
|
||||||
webpack(webpackOptions(routes)).run();
|
webpack(webpackOptions(false, routes)).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
function webpackOptions(routes) {
|
function webpackOptions(production, routes) {
|
||||||
return {
|
return {
|
||||||
// webpack options
|
// webpack options
|
||||||
// entry: "index.html",
|
// entry: "index.html",
|
||||||
entry: "./index.js",
|
entry: { hello: "./index.js" },
|
||||||
mode: "development",
|
mode: production ? "production" : "development",
|
||||||
plugins: [
|
plugins: [
|
||||||
new HTMLWebpackPlugin({ inject: "head" }),
|
new HTMLWebpackPlugin({
|
||||||
|
inject: "head",
|
||||||
|
// template: require.resolve("./template.html")
|
||||||
|
// template: require.resolve(path.resolve(__dirname, "template.html"))
|
||||||
|
template: path.resolve(__dirname, "template.html")
|
||||||
|
}),
|
||||||
new CopyPlugin([
|
new CopyPlugin([
|
||||||
{
|
{
|
||||||
from: "static/**/*",
|
from: "static/**/*",
|
||||||
@ -113,12 +118,12 @@ function webpackOptions(routes) {
|
|||||||
{
|
{
|
||||||
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
||||||
exclude: [/elm-stuff/, /node_modules/],
|
exclude: [/elm-stuff/, /node_modules/],
|
||||||
loader: "file-loader"
|
loader: require.resolve("file-loader")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.(jpe?g|png|gif|svg|html)$/i,
|
test: /\.(jpe?g|png|gif|svg|html)$/i,
|
||||||
exclude: [/elm-stuff/, /node_modules/],
|
exclude: [/elm-stuff/, /node_modules/],
|
||||||
loader: "file-loader"
|
loader: require.resolve("file-loader")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.elm$/,
|
test: /\.elm$/,
|
||||||
|
18
generator/src/template.html
Normal file
18
generator/src/template.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<script>
|
||||||
|
if ("serviceWorker" in navigator) {
|
||||||
|
window.addEventListener("load", () => {
|
||||||
|
navigator.serviceWorker.register("./service-worker.js");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log("No service worker registered.");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body></body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user