import-loader

Webpack loader to import files at once with glob

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
import-loader
101.0.17 years ago8 years agoMinified + gzip package size for import-loader in KB

Readme

import-loader npm version
Webpack loader to import files at once with glob
It's just a concept yet

Install

npm install --save-dev import-loader
or
yarn add --dev import-loader

How to use

Quick
import models from 'import?glob=models/*.js'

Use ?glob

var models = require('import-loader?glob=models/*.js')
// or
var models = require('import?glob=models/*.js')
// or
import models from 'import?glob=models/*.js'

It will be something like that:
var models ={
  'models/User.js': require('models/User.js'),
  'models/Pet.js': require('models/Pet.js'),
}

Use ?name

?name=basename
var models = require('import?glob=models/*.js&name=basename')
// Its will like that
var models = {
  User: require('models/User.js'),
  Pet: require('models/Pet.js'),
}

?name=path
var models = require('import?glob=models/*.js&name=path')
// Its will like that
var models ={
  'models/User.js': require('models/User.js'),
  'models/Pet.js': require('models/Pet.js'),
}

Use ?dir and ?ext

If you have flat list of files in directory, you can drequire like that:
import models from 'import?dir=models'
// or
import models from 'import?dir=models&ext=.server.js'
// or
import components from 'import?dir=components&ext=jsx'

Notes

  1. By default ?ext=js
  2. In ?dir mode by default ?name=basename (if you want path, you need ?name=path)

Use glob .pattern file

You can write your glob pattern If you have a large pattern file
  1. Create a glob pattern file (example: models.pattern)
./models/*.js

  1. Use glob file
var models = require('import!./models.pattern');

Note: Pattern is relative to the file directory.

Other Examples

TODO

  • source map