README
🚀 Welcome to arch-file!
Install
$ npm install arch-file --save
# or
$ npm i arch-file --save
Usage
normal
const NodeArch = require('arch-file')
const arch = new NodeArch()
arch.run()
webpack
const NodeArch = require('arch-file')
module.exports = {
plugins: [
new NodeArch()
]
}
Options
{object|array<object>}
Property
output
{string|object}
./dist.zip
archived file output path.path
output directory.filename
output file name.
context
{string}
.
all path related properties depend on this value, unless others provided absolute path.pattern
{string}
**/*
match pattern, default means match all files under thecwd
directory, see more.cwd
{string}
__dirname
in the current working directory to use matching pattern.ignore
{string|array}
glob patterns to exclude matched.prefix
{string}
/
all files will be under the directory.globOption
{object}
used node-archiver, glob optionarchiverOption
{object}
archiver option see more.source
{object}
the same as outer`s property, if provided, will override outer`s value.pattern
{string}
**/*
cwd
{string}
__dirname
ignore
{string|array}
prefix
{string}
/
globOption
{object}
sources
{array<source>}
source array, if provided, will add allsource
matched files.
Default Option
Normal
DEFAULT_OPTION = {
output: './dist.zip',
context: '.',
archiverOption: { zlib: { level: 9 } },
source: {
pattern: '**/*',
cwd: __dirname,
ignore: '',
prefix: '/',
globOption: {}
}
}
Webpack
DEFAULT_OPTION = {
output: path.join(compilation.outputPath, 'dist.zip'),
context: compilation.context,
archiverOption: { zlib: { level: 9 } },
source: {
pattern: '**/*',
cwd: compilation.outputPath,
ignore: '',
prefix: '/',
globOption: {}
}
}
Scenes
- archive all files under the
example
directory and output toexample
.
const NodeArch = require('arch-file')
const options = {
output: './example/scene1.zip',
cwd: './example'
}
const arch = new NodeArch()
arch.run(options)
- archive
example
directory`s all files and output toexample
, exclude.js
anddemo1
directory.
const NodeArch = require('arch-file')
const options = {
output: './example/scene2.zip',
cwd: './example',
ignore: ['*.js', 'demo1/**']
}
const arch = new NodeArch()
arch.run(options)
- archive
example/demo1
directory`s files toexample1
and archiveexample/demo2
directory`s files toexample2
.
const NodeArch = require('arch-file')
const options = {
output: './example/scene3.zip',
sources: [
{ cwd: './example/demo1', prefix: 'example1' },
{ cwd: './example/demo2', prefix: 'example2' }
]
}
const arch = new NodeArch()
arch.run(options)
- archive
example/demo1
directory`s files andexample/*.md
files and output toexample/example_demo1.zip. archive
example/demo2directory\
s files andexample/*.js
toexample/example_demo2.zip
.
const NodeArch = require('arch-file')
const options = [
{
output: './example/example_demo1.zip',
sources: [
{ cwd: './example/demo1', prefix: 'demo1' },
{ cwd: './example/', pattern: '*.md' }
]
},
{
output: './example/example_demo2.zip',
sources: [
{ cwd: './example/demo2', prefix: 'demo2' },
{ cwd: './example/', pattern: '*.js' }
]
}
]
const arch = new NodeArch()
arch.run(options)
- in webpack, archive project`s all source files to
output.path/scene5.zip
const NodeArch = require('arch-file')
module.exports = {
plugins: [
new NodeArch({
output: {
filename: 'scene5.zip'
},
cwd: __dirname,
ignore: ['node_modules/**', 'dist/**']
})
]
}