jaredpalmer / razzle

✨ Create server-rendered universal JavaScript applications with no configuration
https://razzlejs.org
MIT License
11.1k stars 866 forks source link

Example of razzle with PWA? #1544

Open rwehresmann opened 3 years ago

rwehresmann commented 3 years ago

Is there a working example of razzle with PWA? I know there is a plugin made with this intention, but I just cannot make it work, not sure if there aren't missing instructions there.

If someone could provide an example, it would be great!

fivethreeo commented 3 years ago

https://github.com/jaredpalmer/razzle/discussions/1448

rwehresmann commented 3 years ago

How can I merge this whit my current razzle.config.js below?

module.exports = {
  plugins: ['babel-ts'],
  modify: require('razzle-heroku'),
};
fivethreeo commented 3 years ago

You should install razzle canary. https://github.com/jaredpalmer/razzle/blob/canary/examples/with-heroku/README.md

fivethreeo commented 3 years ago
const { InjectManifest } = require("workbox-webpack-plugin");

module.exports = {
  options: {
    forceRuntimeEnvVars: ['HOST', 'PORT']
  },
  modifyWebpackConfig({
    env: {
      target, 
      dev, 
    },
    webpackConfig, 
    webpackObject, 
    options: {
      razzleOptions,
      webpackOptions, 
    },
    paths, 
  }) {
    const appConfig = Object.assign({}, webpackConfig);
    if (target === "web") {

      appConfig.plugins.push(
        new InjectManifest({ swDest: "sw.js", swSrc: "services.js" }),
      );
    }

    // Do some stuff...
    return appConfig;
  },
};

If you figure this out, please report on your findings 😀

fivethreeo commented 3 years ago

Ts is builtin in canary.

fivethreeo commented 3 years ago

with decorators even https://github.com/jaredpalmer/razzle/tree/canary/examples/with-typeorm-graphql

rwehresmann commented 3 years ago

I couldn't make workbox-webpack-plugin configuration work. There is some issue of invalid MIME type when loading the service worker. However, I gave another try to razzle-plugin-pwa and could make it work now. I think this is the easiest way to go :)