-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
40 lines (32 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var azure = require('azure-storage');
var utils = require('./lib/utils');
function apply(options, compiler) {
// When assets are being emmited (not yet on file system)
compiler.plugin('emit', function (compilation, callback) {
var blobService = azure.createBlobService.apply(azure, options.blobService);
blobService.createContainerIfNotExists(options.container.name, options.container.options, function(error, result, response) {
if(!error){
var assets = utils.getAssets(compilation);
assets.forEach(function(asset) {
blobService.createBlockBlobFromText(options.container.name, asset.filePath, asset.fileContent, { contentSettings: options.metadata }, function(error, result, response) {
if(!error){
console.log("successfully uploaded '" + asset.filePath + "' to container '" + options.container.name + "'");
} else {
console.error(error);
}
});
});
} else {
console.error(error);
}
});
});
}
function AzureStorageDeployWebpackPlugin(options) {
// Simple pattern to be able to easily access plugin
// options when the apply prototype is called
return {
apply: apply.bind(this, options)
};
}
module.exports = AzureStorageDeployWebpackPlugin;