Skip to content

Commit

Permalink
Add options
Browse files Browse the repository at this point in the history
  • Loading branch information
astralarya committed Aug 15, 2016
1 parent aefa925 commit c641b78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ module.exports = {
```

Will create two archives in the same directory as output.path (`__dirname` in the example),
`${output.path}.tar.gz` and `${output.path}.zip`.
`${output.path}.tar.gz` and `${output.path}.zip` containing all compiled assets.
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
let path = require('path');
let fs = require('fs');
let archiver = require('archiver');
'use strict';

function WebpackArchivePlugin(options) {
const path = require('path');
const fs = require('fs');
const archiver = require('archiver');

function WebpackArchivePlugin(options = {}) {
this.options = options;
}

WebpackArchivePlugin.prototype.apply = function(compiler) {
compiler.plugin("after-emit", function(compiler, callback) {
let output = compiler.options.output.path;
const options = this.options;
compiler.plugin('after-emit', function(compiler, callback) {
// Set output location
const output = options.output?
options.output:compiler.options.output.path;

// Create archivers
let zip = archiver('zip');
Expand All @@ -20,7 +26,7 @@ WebpackArchivePlugin.prototype.apply = function(compiler) {
});
tar.pipe(fs.createWriteStream(`${output}.tar.gz`));

//
// Add assets
for(let asset in compiler.assets) {
if(compiler.assets.hasOwnProperty(asset)) {
zip.append(fs.createReadStream(compiler.assets[asset].existsAt), {name: asset});
Expand Down

0 comments on commit c641b78

Please sign in to comment.