Giter Club home page Giter Club logo

Comments (3)

caoxiemeihao avatar caoxiemeihao commented on June 10, 2024

👋 Hey! @shellscape nice to meet you here.
I'm not sure what your source code looks like, but this plugin will only fix some edge cases that Vite/Rollup can't handle (that would definitely have // [vite-plugin-dynamic-import] runtime -S-).
If the importee part of import() in the source code can be correctly processed by Vite/Rollup, then // [vite-plugin-dynamic-import] runtime -S- will not be generated.

from vite-plugin-dynamic-import.

shellscape avatar shellscape commented on June 10, 2024

Ah that's interesting. That would be a nice bit of info for the readme!

from vite-plugin-dynamic-import.

caoxiemeihao avatar caoxiemeihao commented on June 10, 2024

In Vite, only if importee can be resolved normally by resolve(), it can be regarded as a valid import() statement. However, resolve() has many internal restrictions, which leads to the inability to handle many edge scenarios. .

image

source code is here 👉 https://github.com/vitejs/vite/blob/v4.4.11/packages/vite/src/node/plugins/dynamicImportVars.ts#L106-L109


I list some examples of what are considered "edge cases" that need to be handled by vite-plugin-dynamic-import.

// 1. Absolute path are confused with alias, `/root/src` is an alias.
import(`/root/src/views/${id}`)

// 2. Missing slash after `./views`
import(`./views${id}.tsx`)

// 3. Contains both aliases and operations
import('@/views/' + 'foo.js')

// 4. Only aliases and no file extension
import(`@/${id}`)

You can see them in the test files. 👉 test/fixtures/src/main.ts, and output is here 👉 test/fixtures/snapshots/main.ts

from vite-plugin-dynamic-import.

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.