includes-loader
A webpack loader for any text file, and support nested includes with flexible options.
This loader is only tested on webpack 2.1.0-beta.22
Installation
npm install include-text-loader --save-dev
Usage
var confStr = '// confStr is 'foo\nbar\nconf'
Details as follow
directory
├── file.conf
└── foo
├── part.conf
└── bar
└── part.conf
./file.conf
#include "./foo/part"
conf
./foo/part.conf
foo
#include "./bar/part"
./foo/bar/part.conf
bar
Configuration
includes options
default options
includes:pattern:re: /#include\s+?"";*?/index: 1extensions: // the extension will be same to the including file
pattern
An object that should be used to specify how to match the include statement patten.re is the RegExp to match the include statement patten.index is the index of filepath in the matched results
// can be set to a function with filepath argument{var patternif /\.html$/pattern =re: /<!--#\s*?include\s+?virtual=\1\s*?-->/index: 2return pattern}
extensions
An array of extensions that should be used to resolve includes, If you include file with their own extension (e.g. #include './somefile.ext'), you must add an empty string in the array.
// can be set to a function with filepath argument{var extensionsif /\.html$/extensions = '' '.html' '.shtml' '.htm'else if /\.glsl$/extensions = '' '.glsl' '.vert' '.frag'return extensions}
expamle webpack.config
moduleexports =module:module:loaders:test: /\.html$/loader: 'html!includes'test: /\.glsl$/loader: 'includes'includes:{var extensionsif /\.html$/extensions = '' '.html' '.shtml' '.htm'else if /\.glsl$/extensions = '' '.glsl' '.vert' '.frag'return extensions}{var pattern// only custom includes pattern for htmlif /\.html$/pattern =re: /<!--#\s*?include\s+?virtual=\1\s*?-->/index: 2return pattern};
License
MIT (http://www.opensource.org/licenses/mit-license.php)