Git Product home page Git Product logo

vite-plugin-make-offline's Introduction

vite-plugin-make-offline's People

Contributors

juanqp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vite-plugin-make-offline's Issues

Vite build options are overridden

I have my vite build options set, and was using the markOffline() plugin, but the build options were being overwritten, and I didn't understand why, until I looked at the plug-in source code.

For example, I had this

import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react-swc'
import { makeOffline } from "vite-plugin-make-offline";

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
    const env = loadEnv(mode, process.cwd(), '');
    console.log("vite mode....: ...  yep >>> ", mode)
    // other code
    return {
        plugins: [
            react(),
            makeOffline(),
        ],
        base: './',
        build: {
            outDir: "build",
        },
    }
})

The and running npm run build did not generate the build directory. I managed to get it working using this config

// Source from https://github.com/JuanQP/vite-plugin-make-offline without
// overriding all the build options.
import { UserConfig } from "vite";

export function makeOffline() {

  return {
    name: 'iife' as const,
    apply: 'build' as const,
    enforce: 'post' as const,

    config: (config: UserConfig) => {
      config.base = "./"
      config.build = {
        ...config.build,
        rollupOptions: {
          ...config.build?.rollupOptions,
          output: {
            ...config.build?.rollupOptions?.output,
            format: "iife",
          }
        }
      }
    },

    transformIndexHtml(html: string) {
      return html.replace(' type="module" crossorigin ', ' defer ');
    },
  }
}

I did not post a PR as I'm new to front-end development, and Vite, and don't know the ramification of such a change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.