0.0.3 • Published 5 years ago
arch-file v0.0.3
🚀 Welcome to arch-file!
Install
$ npm install arch-file --save
# or
$ npm i arch-file --saveUsage
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.ziparchived file output path.pathoutput directory.filenameoutput 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 thecwddirectory, see more.cwd{string}__dirnamein 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}__dirnameignore{string|array}prefix{string}/globOption{object}
sources{array<source>}source array, if provided, will add allsourcematched 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
exampledirectory and output toexample.
const NodeArch = require('arch-file')
const options = {
output: './example/scene1.zip',
cwd: './example'
}
const arch = new NodeArch()
arch.run(options)- archive
exampledirectory`s all files and output toexample, exclude.jsanddemo1directory.
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/demo1directory`s files toexample1and archiveexample/demo2directory`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/demo1directory`s files andexample/*.mdfiles and output toexample/example_demo1.zip. archiveexample/demo2directory\s files andexample/*.jstoexample/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/**']
})
]
}