Git Product home page Git Product logo

vite-multiple-assets's Introduction

Hi there 👋

I'm Van.

💻  About Me

  • 🤔   Exploring new technologies and developing software solutions to our worlds tech problems.
  • 🤔   Currently I am a senior in the front-end.

🛠  Tech Stack

  • ⚙️   HTML5 SASS CSS3 TailwindCSS JavaScript jQuery Bootstrap Ant-Design Mantine MUI Chakra Next JS Angular React Redux React Query RxJS Tauri Webpack Vite Nx PNPM NPM
  • ⚙️   Git GitLab GitHub
  • 🔧   Visual Studio Code IntelliJ IDEA

🤝🏻  Connect with Me

vite-multiple-assets's People

Contributors

dannymcgee avatar nguyenbatranvan avatar o-alexandrov avatar zxzhuang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vite-multiple-assets's Issues

Issue when converting vite.config to ESM syntax for Vite 6

Vite wants to remove CJS Support in Vite 6.0
Vite Warning in Vite 5.0: (The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.)

so i either need to have "type": "module" set in my package.json, or need to rename vite.config to vite.config.mjs.
but when i do that i get the following error:

failed to load config from C:\Users\[user]\Documents\[projekt]\vite.config.mts
error when starting dev server:
TypeError: DynamicPublicDirectory is not a function
    at file:///C:/Users/[user]/Documents/[projekt]/vite.config.mts.timestamp-1700214793206-f4bc32da7c83e.mjs:77:27
    at loadConfigFromFile (file:///C:/Users/[user]/Documents/[projekt]/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-T98iZFpD.js:66134:15)
    at async resolveConfig (file:///C:/Users/[user]/Documents/[projekt]/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-T98iZFpD.js:65735:28)
    at async _createServer (file:///C:/Users/[user]/Documents/[projekt]/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-T98iZFpD.js:58325:20)
    at async CAC.<anonymous> (file:///C:/Users/[user]/Documents/[projekt]/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/cli.js:764:24)       
 ELIFECYCLE  Command failed with exit code 1.

if i comment out DynamicPublicDirectory it works fine


Workaround:

Currently Vite is only warning, so it can simply be ignored or you can globaly activate "module" and rename vite.config to `vite.config.cjs`.

Output asset folders at a subdirectory

I have a monorepo with this structure:

  • external-assets/
    • asset-1.json
    • asset-2.json
  • frontend/
    • src/
    • public/
      • favicon.ico
    • vite.config.ts

In vite.config.ts I have this:

plugins: [DynamicPublicDirectory(["../external-assets"])]

Per default, anything in the public directory (like favicon.ico) gets served at the root like localhost:8080/favicon.ico. This also means, thanks to your extension allowing me to have essentially multiple public directories, I'm currently able to also access localhost:8080/asset-1.json and localhost:8080/asset-2.json. However, I would prefer everything from the external-assets directory by served under the /external-assets subdirectory, like: localhost:8080/external-assets/asset-1.json.

One way that I'm not fond of is changing my monorepo directory structure like so:

  • external-assets/
    • external-assets/
      • asset-1.json
      • asset-2.json
  • frontend/
    • ...

Proposal: change the plugin's first argument (dirAssets in DynamicPublicDirectory(dirAssets, mimeTypes)) from string[] to (string | { in: string, out: string })[] so the additional asset directories can each be specified as just an input (where the files are dumped alongside the public folder contents) or as an object listing both an input and output, where the latter specifies the folder(s) that contain its contents. So my use case explained above would become:

plugins: [
    DynamicPublicDirectory([
        { in: "../external-assets", out: "external-assets" }
    ])
]

[Bug] Cannot set headers after they are sent to the client

Hi,
I am using this plugin and I have a log who is emitted on vite. This issue is not fatal, I can access to my assets but i prefer to share it to fix it :

GET http://localhost:3100/fonts/Steradian/steradian-rg-webfont.woff2
An unhandled error occured: Error: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:405:5)
    at ServerResponse.setHeader (node:_http_outgoing:648:11)
    at handleNodeResponse (file:///home/quentin/Documents/dev/madeformed/starter-web/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/solid-start/node/fetch.js:171:16)
    at startHandler (file:///home/quentin/Documents/dev/madeformed/starter-web/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/solid-start/dev/server.js:140:7)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Regards

Plugin not Working do to difference in "\" and "/"

Environment:
Windows 10; Vite 4.4.7

Issue:
fileObject can contain a path that is only different to file in the separator that is used.

example:
fileObject[i].files[n] = "C:\Path\to\Folder/Foo.js"
file = "C:\Path\to\Folder\Foo.js"
=> only the last separator before Foo.js is different

my proposed solution:
instead of fileObject[i].files.includes(file) fileObject[i].files.some(f => path.relative(f, file) === "")

allow to extend and/or have default for mime types.

I have a static asset without an extension (in my case , a file called userinfo as I'm mimicing an OIDC server ). In the default implementation, this results in the following error: TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "Content-Type".

I ended up patching the package to add the file + content type I needed.

It would be great if this plugin would provide the following functionalities:

  • have a default mime type when none was found (instead of undefined + an error when running with vite)
  • allow to overwrite said default
  • add custom mime types
  • extend mime type check to support the actual filename and/or a glob

Request static file with query return 404

Environment:
Windows 11; Vite 4.5.1;

Request static file with query return 404

const f = 'iconfont.woff2'
const file = 'iconfont.woff2?t=1702609282724'
path.relative(f, file) // => "..\\iconfont.woff2?t=1702609282724"
path.relative(f, file) === "" // false

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.