1.0.0 • Published 7 years ago
file-copy-parse v1.0.0
file-copy-parse
A NodeJS and Webpack plugin to copy (UTF) and parse files from one location to another. The parsing process contains the following (optional tasks) tasks:
- Compression. It does only the most basic compression, ie. removes all extra white spaces (extra spaces, line feeds, tabs etc.).
- Template literal replacement. Any string defined as a template variable in the "templateVars" property will be replaced by the value of your choice
- Comment Removal. Can remove HTML and Javascript (single and multi-line) comments
Requirements
- NodeJS >= 5
Installation
npm install file-copy-parse --save-dev
Import
All you need to do is require it in your webpack config, eg.:
const MarkupGenerator = require('file-copy-parse');
...
{
entry: {
...
}
...
plugins: [
new MarkupGenerator(options)
]
}
API Documentation
TemplateParser
Generate a compressed file at a target location, and replace any template literal variables present with a specific value
Parameters
params
(array | object) The configuration for one or more sources and destinationsparams.sourceFiles
(string | array) Either the list of files you need to minify and cache bust, or a globbing patternparams.sourceRoot
string The root folder (lowest common folder) that the source files are located inparams.targetRoot
string The root folder (lowest common folder) that the processed files should be written toparams.templateVars
(object | function)? An object (or function returning an object) that will contain the values associated with any template literal variables included in the source file If you have the keyword 'hash' as one of the templateVar values, then the md5 hash of the target file will replace the 'hash' placeholder. Example usage: templateVars: { '?cache=true': '?hash' } (optional, default{}
)params.compress
boolean? Remove all extra white spaces, line feeds, tabs etc. (optional, defaultfalse
)params.discardComments
boolean? Remove all Javascript and HTML comments from the file (optional, defaultfalse
)params.webpack
boolean? Determines whether or not the method should be executed as a Webpack plugin. The 'hash' replacement works only as a Webpack plugin (optional, defaulttrue
)
Returns void
Changelog
- 1.0.0
- Bug fixes
Updated the logic in the "done" event of the Webpack flow
0.1.1
- Minor bug fixes and unit tests
- Added MD5 hash functionality
- Added Travis CI functionality
0.0.8
- Initial version