GithubHelp home page GithubHelp logo

Comments (12)

userquin avatar userquin commented on September 28, 2024 2

@YunYouJun vitejs/vite#1791 (comment)

from vite-ssg.

userquin avatar userquin commented on September 28, 2024

@YunYouJun use typeof window !== 'undefined' instead, on SSR/SSG navigator is not defined.

See #21 (comment)

from vite-ssg.

YunYouJun avatar YunYouJun commented on September 28, 2024

@YunYouJun use typeof window !== 'undefined' instead, on SSR/SSG navigator is not defined.

See #21 (comment)

In fact, I tried to do it, but it didn't work either. (typeof window !== 'undefined'

from vite-ssg.

userquin avatar userquin commented on September 28, 2024

@YunYouJun I'll take a look at your repo...

from vite-ssg.

YunYouJun avatar YunYouJun commented on September 28, 2024

@YunYouJun I'll take a look at your repo...

Thanks, main file is https://github.com/YunYouJun/web-resume/blob/main/src/pages/editor.vue.

from vite-ssg.

userquin avatar userquin commented on September 28, 2024

@YunYouJun what are you using npm, pnpm or yarn? There is no lock file on your repo...

from vite-ssg.

YunYouJun avatar YunYouJun commented on September 28, 2024

@YunYouJun what are you using npm, pnpm or yarn? There is no lock file on your repo...

Because lockfile is large and it is not a project that requires a fixed dependency, I ignored the lock file.

Yarn or pnpm is OK, I'm currently using pnpm.

from vite-ssg.

userquin avatar userquin commented on September 28, 2024

@YunYouJun I have your repo build working:

Change serve script with: "serve": "vite preview" (remove the hyphen).

Change src/pages/editor.vue just remove import * as monaco from 'monaco-editor' and onMounted configure this:

onMounted(async() => {
  const txt = await useResume(route.query.url as string)
  resumeTxt.value = txt
  console.log(txt)
  if (typeof window !== 'undefined' && container.value) {
    const monaco = await import('monaco-editor')
    monaco.editor.create(container.value, {
      value: resumeTxt.value,
      language: 'yaml',
      theme: 'vs-dark',
      wordWrap: 'on',
    })
  }
})

Since we are using monaco editor we need to change rollup options on vite config file: on SSG build the monaco dep will go to the temporary main.js (5MB) (the entry point for vite-ssg for build) and then will fail, since there is some usage to detect browser:

// vite.config.ts
...
...
import path from 'path'

const prefix = 'monaco-editor/esm/vs'
// import yaml from '@rollup/plugin-yaml'

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
...
...
  build: {
    rollupOptions: {
      output: {
        inlineDynamicImports: false,
        manualChunks: {
          jsonWorker: [`${prefix}/language/json/json.worker`],
          cssWorker: [`${prefix}/language/css/css.worker`],
          htmlWorker: [`${prefix}/language/html/html.worker`],
          tsWorker: [`${prefix}/language/typescript/ts.worker`],
          editorWorker: [`${prefix}/editor/editor.worker`],
        },
      },
    },
  },

  // https://github.com/antfu/vite-ssg
  ssgOptions: {
    script: 'async',
    formatting: 'minify',

imagen

from vite-ssg.

YunYouJun avatar YunYouJun commented on September 28, 2024

It works. Thank you very much!

from vite-ssg.

YunYouJun avatar YunYouJun commented on September 28, 2024

Is it possible for us to do this automatically with vite-ssg? For example, detects the 'worker .js' suffix name when packaging.

from vite-ssg.

userquin avatar userquin commented on September 28, 2024

@YunYouJun the problem is that we don't know if the worker is pre-bundled or not so the problem is on the user land, we cannot assume all workers requires pre-bundle them and of course how to do it ;).

from vite-ssg.

YunYouJun avatar YunYouJun commented on September 28, 2024

Okay, I see.

from vite-ssg.

Related Issues (20)

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.