Giter VIP home page Giter VIP logo

Comments (15)

aa900031 avatar aa900031 commented on July 18, 2024 1

@userquin @danielroe minimal reproduction is here, but stackblitz can't exec sharp, so I think should download this project and run at local

https://stackblitz.com/edit/reproduce-vite-pwa-nuxt-assets-custom-src-gwjm7u?file=README.md

from nuxt.

danielroe avatar danielroe commented on July 18, 2024 1

Nuxt resolves the public directory like this: resolve(nuxt.options.srcDir, nuxt.options.dir.public). dir.public is public in v4 but will be a fully resolved directory in v4, defaulting to resolve(nuxt.options.rootDir, 'public').

from nuxt.

userquin avatar userquin commented on July 18, 2024 1

Nuxt resolves the public directory like this: resolve(nuxt.options.srcDir, nuxt.options.dir.public). dir.public is public in v4 but will be a fully resolved directory in v4, defaulting to resolve(nuxt.options.rootDir, 'public').

So... nuxt image not yet compatible with v4 layout

from nuxt.

danielroe avatar danielroe commented on July 18, 2024 1

resolve(nuxt.options.srcDir, options.dir) should correctly resolve to resolve(nuxt.options.rootDir, 'public') in this case.

from nuxt.

userquin avatar userquin commented on July 18, 2024

Nuxt 3.12.0 (nightly) also failing when building and generating dts pwa icons (weird, in dev works)

/cc @danielroe maybe some paths in dev different from build/prepare commands

from nuxt.

userquin avatar userquin commented on July 18, 2024

@aa900031 can you provide minimal reproduction?

from nuxt.

userquin avatar userquin commented on July 18, 2024

Daniel, in Nuxt 3.12 now we have 2 Vite roots, server (root folder) and client (now it is app folder) and so we need to change the logic: since we've the image relative to root folder we cannot use the same logic fro server and client.

Moving pwa-assets.config file inside app works in dev but not generating pwa icons on build: pwa icons types in dts also missing.

EDIT: adding pwa-assets-config with relative image works, but we need 2 pwa assets config files.

from nuxt.

userquin avatar userquin commented on July 18, 2024

@aa900031 we need to review the logic in vite pwa plugin, we'll need to add some hooks to resolve pwa assets configuration and pwa image, by default should work as it is right now (add resolve config and resolve pwa image).

In the meantime use default nuxt layout or switch to PWA Assets Generator CLI, sorry.

from nuxt.

aa900031 avatar aa900031 commented on July 18, 2024

@userquin Thanks for your reply, I'll use CLI to handle it for now

from nuxt.

userquin avatar userquin commented on July 18, 2024

@aa900031 I guess I've found the problem, testing with your reproduction, maybe we don't need to change pwa plugin.

from nuxt.

userquin avatar userquin commented on July 18, 2024

With the new version I'm going to release (0.8.0), you will need to move pwa-assets.config.ts inside src folder and:

  1. configure public dir properly
// nuxt.config.ts
import { resolve } from 'node:path'
...
export default defineNuxtConfig({
  nitro: {
    publicAssets: [{ dir: resolve(process.cwd(), 'src/public') }]
  },
  dir: {
    public: 'src/public',
  },
  1. or move public folder to root (like new v4 layout, using app instead src), you also need to change image name in pwa-assets.config.ts:
// src/pwa-assets.config.ts
export default defineConfig({
  ...
  images: '../public/favicon.svg',
})

from nuxt.

aa900031 avatar aa900031 commented on July 18, 2024

I think change dir.public is not a good idea, that will be have compatibility for other modules.

let me find some modules later

from nuxt.

aa900031 avatar aa900031 commented on July 18, 2024

If use nuxt/image modules and set dir.public like your guide that will not working

because nuxt/image resolve public dir with srcDir: https://github.com/nuxt/image/blob/3a98a685746b5be2188ddf59d091a4f3e525067b/src/module.ts#L60

from nuxt.

aa900031 avatar aa900031 commented on July 18, 2024

If nuxt/image resolves the public path to src/public in the context of setting srcDir: 'src'

Continuing with the previous context, I added the setting dir.public: 'src/public' suggested by @userquin, then the public path I will get in nuxt/image will be src/src/public, right? Such a result should be unexpected

The above versions are all in Nuxt 3

from nuxt.

userquin avatar userquin commented on July 18, 2024

Continuing with the previous context, I added the setting dir.public: 'src/public' suggested by @userquin, then the public path I will get in nuxt/image will be src/src/public, right? Such a result should be unexpected

I need to review the code, it will take more time since I need to rewrite the pwa plugin logic, in the meantime use the CLI, sorry again.

The above versions are all in Nuxt 3

Yes, but we're talking about a breaking change in Nuxt 3.12, you can try using nuxt 3.12 (npm:nuxt-nightly@latest) moving public folder to root, both nuxt image and pwa will work (use my previous 2).

from nuxt.

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.