UNPKG

2.77 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 _path = require("path");
14
15var _path2 = _interopRequireDefault(_path);
16
17var _generateRobotstxt = require("generate-robotstxt");
18
19var _generateRobotstxt2 = _interopRequireDefault(_generateRobotstxt);
20
21function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
25var RobotstxtWebpackPlugin = function () {
26 function RobotstxtWebpackPlugin() {
27 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
29 _classCallCheck(this, RobotstxtWebpackPlugin);
30
31 this.options = Object.assign({}, options);
32 }
33
34 _createClass(RobotstxtWebpackPlugin, [{
35 key: "apply",
36 value: function apply(compiler) {
37 var _this = this;
38
39 compiler.plugin("emit", function (compilation, callback) {
40 return _this.generate(compilation, callback);
41 });
42 }
43 }, {
44 key: "generate",
45 value: function generate(compilation, callback) {
46 var options = this.options;
47
48
49 return (0, _nodeify2.default)((0, _generateRobotstxt2.default)(options).then(function (contents) {
50 var dest = options.dest ? _path2.default.join(options.dest, "robots.txt") : "robots.txt";
51
52 compilation.assets[dest] = {
53 size: function size() {
54 return Buffer.byteLength(this.source(), "utf8");
55 },
56 source: function source() {
57 return contents;
58 }
59 };
60
61 return contents;
62 }), function (error) {
63 if (error) {
64 compilation.errors.push(error);
65 }
66
67 return callback();
68 });
69 }
70 }]);
71
72 return RobotstxtWebpackPlugin;
73}();
74
75exports.default = RobotstxtWebpackPlugin;
\No newline at end of file