From e2c7cbad73c57c1067b90115954658c431649df5 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 14 Aug 2019 15:15:00 -0700 Subject: [PATCH] Use template for html file that loads service worker file. --- generator/src/develop.js | 21 +++++++++++++-------- generator/src/template.html | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 generator/src/template.html diff --git a/generator/src/develop.js b/generator/src/develop.js index 7d7b6870..a46e80d5 100644 --- a/generator/src/develop.js +++ b/generator/src/develop.js @@ -9,7 +9,7 @@ const PrerenderSPAPlugin = require("prerender-spa-plugin"); module.exports = { start, run }; function start({ routes }) { - const compiler = webpack(webpackOptions(routes)); + const compiler = webpack(webpackOptions(true, routes)); const app = express(); app.use(middleware(compiler, { publicPath: "/" })); @@ -36,17 +36,22 @@ function start({ routes }) { } function run({ routes }) { - webpack(webpackOptions(routes)).run(); + webpack(webpackOptions(false, routes)).run(); } -function webpackOptions(routes) { +function webpackOptions(production, routes) { return { // webpack options // entry: "index.html", - entry: "./index.js", - mode: "development", + entry: { hello: "./index.js" }, + mode: production ? "production" : "development", 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([ { from: "static/**/*", @@ -113,12 +118,12 @@ function webpackOptions(routes) { { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, exclude: [/elm-stuff/, /node_modules/], - loader: "file-loader" + loader: require.resolve("file-loader") }, { test: /\.(jpe?g|png|gif|svg|html)$/i, exclude: [/elm-stuff/, /node_modules/], - loader: "file-loader" + loader: require.resolve("file-loader") }, { test: /\.elm$/, diff --git a/generator/src/template.html b/generator/src/template.html new file mode 100644 index 00000000..7b37878d --- /dev/null +++ b/generator/src/template.html @@ -0,0 +1,18 @@ + + + + + + + + + +