| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
npm install preprocessor-loader --save-dev
The preprocess-loader is a loader I developed to support the Webpack Module Bundler project. The preprocess-loader provides the ability to preprocess source files through user defined regular expressions, macros, and callback routines. Additionally it has the ability out of the box to replace common tags like LINE and FILE with line number and filename. Furthermore, all user defined logic can be applied to line scope or source scope.
To simply use the LINE or FILE feature you can either specify it in the configuration file below or by simply adding values to the query string.
Below is an example of using the preprocess-loader and chaining the output to babel-loader.
{
test: /\.jsx?$/,
loaders: ["babel","preprocessor?line&file&config="+path.join(__dirname,'./cfg/preprocess.json')],
exclude: /node_modules/
},All parameters are optional in the query string. As previously mentioned you may optionally specify the line or file values in the configuration file.
A sample configuration file may be found below, notice it is simply json.
{
"line" : true,
"file" : true,
"regexes" : [
{
"fileName" : "all",
"scope" : "line",
"regex" : "__FOO__",
"flags" : "g",
"value" : "FOO"
}
],
"macros" : [
{
"fileName" : "all",
"scope" : "line",
"name" : "MYMACRO(x,b)",
"flags" : "g",
"inline" : "function doSomething(x, b) {console.log(x+b);}"
}
],
"callbacks" : [
{
"fileName": "all",
"scope" : "line",
"callback": "(function fooA(line, fileName, lineNumber) { line = line.replace(new RegExp('TEST'),'HELLO','g'); return line; })"
},
{
"fileName": "all",
"scope" : "source",
"callback": "(function fooB(source, fileName) { console.log('FILENAME is:'+fileName); return source; })"
}
]
}##regexes are regular expressions
##macros are like regular expressions (They operate in the same way) Except they allow for macros to be expanded inline in the code like the C preprocessor.
##callbacks are user defined functions
ALL CALLBACKS MUST RETURN THE LINE OR SOURCE WHEN PROCESSING IS COMPLETE
| Back | FazBrowse Home | New Git URL |