UNPKG

2.38 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
9var _nodeify = require("nodeify");
10
11var _nodeify2 = _interopRequireDefault(_nodeify);
12
13var _generateRobotstxt = require("generate-robotstxt");
14
15var _generateRobotstxt2 = _interopRequireDefault(_generateRobotstxt);
16
17function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20
21var RobotstxtWebpackPlugin = function () {
22 function RobotstxtWebpackPlugin() {
23 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
24
25 _classCallCheck(this, RobotstxtWebpackPlugin);
26
27 this.options = Object.assign({
28 filePath: "robots.txt"
29 }, options);
30 }
31
32 _createClass(RobotstxtWebpackPlugin, [{
33 key: "apply",
34 value: function apply(compiler) {
35 var _this = this;
36
37 compiler.plugin("emit", function (compilation, callback) {
38 return _this.generate(compilation, callback);
39 });
40 }
41 }, {
42 key: "generate",
43 value: function generate(compilation, callback) {
44 var _this2 = this;
45
46 return (0, _nodeify2.default)((0, _generateRobotstxt2.default)(this.options).then(function (contents) {
47 compilation.assets[_this2.options.filePath] = {
48 size() {
49 return Buffer.byteLength(this.source(), "utf8");
50 },
51 source() {
52 return contents;
53 }
54 };
55
56 return contents;
57 }), function (error) {
58 if (error) {
59 compilation.errors.push(error);
60 }
61
62 return callback();
63 });
64 }
65 }]);
66
67 return RobotstxtWebpackPlugin;
68}();
69
70exports.default = RobotstxtWebpackPlugin;
\No newline at end of file