Skip to content

Instantly share code, notes, and snippets.

@cahnory
Created January 27, 2017 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cahnory/ef5887225eac53ad50fdc660ba8546c1 to your computer and use it in GitHub Desktop.
Save cahnory/ef5887225eac53ad50fdc660ba8546c1 to your computer and use it in GitHub Desktop.
Idée vite jetée à propos des bundlers

Utilisation d'une fonction d'import propre au bundler

Aujourd'hui, webpack nous permet d'inclure un asset comme s'il s'agissait d'un fichier javascript :

import style from './style.css'

Mais les avantages de cette approches ne sont ils pas inférieurs aux inconvéniants ?

Une autre approche, plus explicite, serait d'utiliser une fonction :

  import bundle from 'bundle'
  const style = bundle('./style.css')

Celle si pourrait, même en l'absence de bundler, loader les fichiers d'assets.

Les cons

  • importer le bundler dans chaque fichier qui importera des assets
  • syntaxe moins naturelle (comparé à l'import standard)

Les pros

  • fonctionne quel que soit l'environnement
  • fonctionne même sans avoir été "bundlé"
  • facilite le partage/publication du code (encore plus si l'on sépare loader et bundler)
@Macxim
Copy link

Macxim commented Jan 27, 2017

Using an import function specific to the bundler

Nowadays, webpack allows us to include an asset as if it were a JavaScript file:

import style from './style.css'

With this approach, don't the disadvantages outweigh the benefits?

Another way to do it would be using a function:

  import bundle from 'bundle'
  const style = bundle('./style.css')

Even without any bundler, the assets could be loaded.

Cons

  • import the bundler inside each file which will import assets
  • less natural syntax (compared to standard import)

Pros

  • works in any environment
  • works even without being bundled
  • makes code publication/sharing easier (even more if we separate loader and bundler)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment