UNPKG

4.05 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 _fs = require('fs');
10
11var _fs2 = _interopRequireDefault(_fs);
12
13var _lodash = require('lodash');
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
19function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
20
21function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
22
23var gulpWebpack = void 0;
24
25var WebpackTask = function (_Elixir$Task) {
26 _inherits(WebpackTask, _Elixir$Task);
27
28 /**
29 * Create a new JavaScriptTask instance.
30 *
31 * @param {string} name
32 * @param {GulpPaths} paths
33 * @param {object|null} options
34 */
35 function WebpackTask(name, paths, options) {
36 _classCallCheck(this, WebpackTask);
37
38 var _this = _possibleConstructorReturn(this, (WebpackTask.__proto__ || Object.getPrototypeOf(WebpackTask)).call(this, name, null, paths));
39
40 _this.options = options;
41
42 if (_fs2.default.existsSync('webpack.config.js')) {
43 _this.userWebpackConfig = require(process.cwd() + '/webpack.config.js');
44 }
45 return _this;
46 }
47
48 /**
49 * Lazy load the task dependencies.
50 */
51
52
53 _createClass(WebpackTask, [{
54 key: 'loadDependencies',
55 value: function loadDependencies() {
56 gulpWebpack = require('webpack-stream');
57 }
58
59 /**
60 * Build up the Gulp task.
61 */
62
63 }, {
64 key: 'gulpTask',
65 value: function gulpTask() {
66 return gulp.src(this.src.path).pipe(this.webpack()).on('error', this.onError()).pipe(this.minify()).on('error', this.onError()).pipe(this.saveAs(gulp)).pipe(this.onSuccess());
67 }
68
69 /**
70 * Run the files through Webpack.
71 */
72
73 }, {
74 key: 'webpack',
75 value: function webpack() {
76 this.recordStep('Transforming ES2015 to ES5');
77 this.recordStep('Writing Source Maps');
78
79 return gulpWebpack(this.mergeConfig(), require('webpack'));
80 }
81
82 /**
83 * Merge the Webpack config.
84 *
85 * @return {object}
86 */
87
88 }, {
89 key: 'mergeConfig',
90 value: function mergeConfig() {
91 var defaultConfig = {
92 output: { filename: this.output.name }
93 };
94
95 return (0, _lodash.mergeWith)(defaultConfig, Elixir.webpack.config, this.userWebpackConfig, this.options, function (objValue, srcValue) {
96 if ((0, _lodash.isArray)(objValue)) {
97 return objValue.concat(srcValue);
98 }
99 });
100 }
101 }]);
102
103 return WebpackTask;
104}(Elixir.Task);
105
106exports.default = WebpackTask;
\No newline at end of file