Require a whole directory of trees in bulk
MIT License
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.
npm i required-loader --save-dev
Add in your code comment:
/* input string in code */
//@require "./modules/**/index.js"
/* output */
require('./modules/one/index.js');
require('./modules/two/index.js');
require('./modules/three/index.js');
Add in your code comment:
//@require "./modules/**/index.js?import[]=angular,go={hello:'world'}"
//@require "./modules/**/index.js?import[]=angular,import[]=$=jquery,go={hello:'world'}"
//@require "./**/!(index|config|run)*"
//@require "./**/*"
//@require "./**/*.html"
/* input string in style file */
@require "./**/!(app|bootstrap).css";
@require "./**/*.less";
@require "./**/*.scss";
@require "./**/*.styl";
/* output */
@import 'style/header.css';
@import 'style/layout.css';
@import 'style/menus.css';
{
test: /\.js$/,
loader: 'required?import[]=angular',
}
OR
loaders: ["ng-annotate","babel","required?import[]=angular,params={ip:'0.0.0.0'}"]
{
test: /\.css$/,
loader: 'required',
}
OR
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:'0.0.0.0'} 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.!
or ^
then it matches!(pattern|pattern|pattern)
Matches anything that does not match?(pattern|pattern|pattern)
Matches zero or one occurrence of the+(pattern|pattern|pattern)
Matches one or more occurrences of the*(a|b|c)
Matches zero or more occurrences of the patterns provided@(pattern|pat*|pat?erN)
Matches exactly one of the patterns