node package manager



Loader receives a file tree from a template and import them with the necessary parameters settings.

It can be used to import any kind of files. You can use it in javascript files or style files. Works great with ng-include and ng-cache when developing angular applications.

Use with angular

Support Webpack 1.x and Webpack 2.x


npm i required-loader --save-dev

Simple Usage

Add in your code comment:

/* input string in code */
//@require "./modules/**/index.js" 
/* output */

Usage with import props

Add in your code comment:

//@require "./modules/**/index.js?import[]=angular,go={hello:'world'}" 
  • If the import parameters are set in the webpack.config.js file and in @require comment, they both will be imported into the included files

More examples

//@require "./modules/**/index.js?import[]=angular,import[]=$=jquery,go={hello:'world'}" 
//@require "./**/!(index|config|run)*" 
//@require "./**/*" 
//@require "./**/*.html" 

Usage in CSS/SCSS/STYL files

/* input string in style file */
@require "./**/!(app|bootstrap).css";
/* output */
@import 'style/header.css';
@import 'style/layout.css';
@import 'style/menus.css';


JS loader

test: /\.js$/,
  loader: 'required?import[]=angular',
loaders: ["ng-annotate","babel","required?import[]=angular,params={ip:''}"]

CSS loaders

test: /\.css$/,
  loader: 'required',
loader: ExtractTextPlugin.extract("style","css?sourceMap!postcss!required")


Param Description
import import modules in required scripts
params import params in required scripts. It can be any variable name. Params in loader === var params = {ip:''} in file witch require

The following characters have special magic meaning when used in a path portion:

  • * Matches 0 or more characters in a single path portion
  • ? Matches 1 character
  • [...] Matches a range of characters, similar to a RegExp range. If the first character of the range is ! or ^ then it matches any character not in the range.
  • !(pattern|pattern|pattern) Matches anything that does not match any of the patterns provided.
  • ?(pattern|pattern|pattern) Matches zero or one occurrence of the patterns provided.
  • +(pattern|pattern|pattern) Matches one or more occurrences of the patterns provided.
  • *(a|b|c) Matches zero or more occurrences of the patterns provided
  • @(pattern|pat*|pat?erN) Matches exactly one of the patterns provided

If you find a mistake, don't be lazy, write. Thank you.

Pull request welcome