Code Monkey home page Code Monkey logo

Comments (14)

WarrenJones avatar WarrenJones commented on May 24, 2024 1

Hey again ๐Ÿ‘‹ Thanks for your help The main problem I think is that since there are two files with the same, but different extensions, this plugin converts them to the same variable ๐Ÿ‘‡

image image

I've moved away from the require statements and am trying a solution with imports, I'll lay down a repo where the issue can be replicated.

I think the latest version can solve the problem of same file name,different extensions,I just wrote some test code,the default variable will be turn into fileName_extension_default format.

from vite-plugin-require-transform.

WarrenJones avatar WarrenJones commented on May 24, 2024 1
//same path,different extension
const testCaseA = require("caseA.extA?aaa");
const testCaseB = require("caseA.extB?bbb").default;

console.log("caseA", testCaseA)
console.log("caseB", testCaseB)`

will be turn into:

import { default as _vite_plugin_require_transform_caseA_extB_bbb_default } from "caseA.extB?bbb";
import _vite_plugin_require_transform_caseA_extA_aaa from "caseA.extA?aaa";
//same path,different extension
const testCaseA = _vite_plugin_require_transform_caseA_extA_aaa;
const testCaseB = _vite_plugin_require_transform_caseA_extB_bbb_default;
console.log("caseA", testCaseA);
console.log("caseB", testCaseB);

from vite-plugin-require-transform.

WarrenJones avatar WarrenJones commented on May 24, 2024

Can you take a screenshot about the error? maybe the error is not about the extensions I think, it's about the format require(...).default, let's see what the real problem is and I'm glad to fix it

from vite-plugin-require-transform.

davidsmorais avatar davidsmorais commented on May 24, 2024

Hey ๐Ÿ‘‹
Thanks for replying.

From what I've seen, this started to happen with .css & .ttf files with the same name, here's my case:
image
image
& here's the error
image

from vite-plugin-require-transform.

davidsmorais avatar davidsmorais commented on May 24, 2024

In the case of audiosprites, which require to have the same name across different formats, this is also a blocker:
image
image

Basically, if we could add an option to suffix the variables with the file format, I think it would solve the issue

from vite-plugin-require-transform.

WarrenJones avatar WarrenJones commented on May 24, 2024

checkout the newest version,with readme about case 3,it's supported now!

from vite-plugin-require-transform.

davidsmorais avatar davidsmorais commented on May 24, 2024

Hey ๐Ÿ‘‹
Thanks for your switf action ๐Ÿ‘
I gave it a try and now it seems to be losing the file extension when importing:
image
Relevant code:
image

EDIT: Just posting my config

    requireTransform(
      (fileRegex = /.ts$|.tsx$|.png$|.css$|.json$|.ttf$|.ac3$|.ogg$|.m4a$|.mp3$/),
      (prefix = "vite_require_transform_"),
      (importPathHandler = (requirePath) => {
        return requirePath.replace(".", "_");
      })
    ),

from vite-plugin-require-transform.

WarrenJones avatar WarrenJones commented on May 24, 2024

Thanks for your patient,I think this time would be fixed,just check the newest version again

from vite-plugin-require-transform.

davidsmorais avatar davidsmorais commented on May 24, 2024

Hey man ๐Ÿ‘‹
Thanks again for comming up with a solution.
I gave it a shot and while it did indeed fixed the required errors, I now have the wrong file being loaded.
image

I'm still not 100% clear if this is something I'm doing wrong, but then again, I'm migrating from webpack, so I expected this to work almost out of the box ๐Ÿ˜†
I'll post here if I manage to get a handle on the transpiled files

from vite-plugin-require-transform.

davidsmorais avatar davidsmorais commented on May 24, 2024

I've tried to move the .default to another part of the app, and I'm back to the first error.
Here's the relevant code:
image
image
ImagesHudShiftKeyFrames is an empty enum

The error
image

And my config:

 defineConfig({
  plugins: [
    requireTransform(
      (fileRegex = /.ts$|.tsx$|.png$|.css$|.json$|.ttf$|.ac3$|.ogg$|.m4a$|.mp3$/),
      (prefix = "vite_require_transform_"),
      (importPathHandler = (requirePath) => {
        return requirePath.replace(".", "_");
      })
    ),
  ],
...})

from vite-plugin-require-transform.

WarrenJones avatar WarrenJones commented on May 24, 2024

Thanks for your patitent again and I'm glad to solve the problem.I am not sure if it is the cause the problem of the plugin,Actually I can not understand the real problem that you propose this time,maybe you can provide a minimal repo link that can reproduce the problem you ran into.

from vite-plugin-require-transform.

davidsmorais avatar davidsmorais commented on May 24, 2024

Hey again ๐Ÿ‘‹
Thanks for your help
The main problem I think is that since there are two files with the same, but different extensions, this plugin converts them to the same variable ๐Ÿ‘‡

image
image

I've moved away from the require statements and am trying a solution with imports, I'll lay down a repo where the issue can be replicated.

from vite-plugin-require-transform.

davidsmorais avatar davidsmorais commented on May 24, 2024

Thanks for the help :)

from vite-plugin-require-transform.

WarrenJones avatar WarrenJones commented on May 24, 2024

Thanks for the help :)

you're welcome.It's my pleasure hahah to make sth to help anyone in the world,my friend

from vite-plugin-require-transform.

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.