Git Product home page Git Product logo

Comments (10)

yuanchuan avatar yuanchuan commented on June 18, 2024

Use module or mapping:

autoImport({
  components: [],

  mapping: {
    SomeLib: `import SomeLib from 'some-lib'`
  }
})

from sveltekit-autoimport.

bwklein avatar bwklein commented on June 18, 2024

Do you have an example or docs for these features? I'm not sure how I would use that in my case.

from sveltekit-autoimport.

bwklein avatar bwklein commented on June 18, 2024

For example, I have a <Video v="XXXXXX"/> component in my markdown. It comes from import {Video} from tecitheme/components/Video.svelte'

If I add that import line to the script in markdown the component works as expected.

from sveltekit-autoimport.

yuanchuan avatar yuanchuan commented on June 18, 2024

Yeah there are examples at the bottom of readme file.

autoImport({
  /* .. */
  mapping: {
    Video: `import {Video} from 'tecitheme/components/Video.svelte'`
  }
})

from sveltekit-autoimport.

yuanchuan avatar yuanchuan commented on June 18, 2024

It means how/where to import the Video component. They can be component, variable, or a function:

autoImport({
  /* .. */
  mapping: {

    VideoX: `import { Video as VideoX } from 'tecitheme/components/Video.svelte'`,

    T: `import T from './lib/language/get-text.js'`,
   
    /* I wouldn't suggest this */
    GLOBAL_VAR: `const GLOBAL_VAR = 'hello world';`,
  }
})

from sveltekit-autoimport.

bwklein avatar bwklein commented on June 18, 2024

Ok, instead of mapping all of the components individually, would it be possible to add the node module to the "components" array and have them all imported automatically? That's how it works if they are in a local folder, like ./src/lib/components.

from sveltekit-autoimport.

yuanchuan avatar yuanchuan commented on June 18, 2024

I suggest import them manually and explicitly for the third-party components. There's also a module option for selecting multiple items for a module.

autoImport({
  /* .. */
  module: {
    'some-component-lib': ['Video', 'Caption']
  }
})

Which means:

import { Video, Caption } from 'some-component-lib'

from sveltekit-autoimport.

bwklein avatar bwklein commented on June 18, 2024

Ok this works well for me. Thank you.

from sveltekit-autoimport.

bwklein avatar bwklein commented on June 18, 2024
autoImport({
  /* .. */
  module: {
    'some-component-lib': ['Video', 'Caption']
  }
})

How would you do this in my case where the components are in the 'components' subdirectory of the theme?

BTW, the following code works for me now.

mapping: {
    Video: `import Video from 'tecitheme/components/Video.svelte'`
  }

from sveltekit-autoimport.

yuanchuan avatar yuanchuan commented on June 18, 2024

The package tecitheme is missing an entry file like index.js for exporting all packages outside. So you have to import them one by one

from sveltekit-autoimport.

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.