includeFilesLoader.js 844 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var _loaderUtils = require('loader-utils');
  3. var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
  4. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  5. // Note: no export default here cause of Babel 6
  6. module.exports = function includeFilesLoader(sourceCode) {
  7. var _this = this;
  8. if (this.cacheable) {
  9. this.cacheable();
  10. }
  11. var loaderOptions = _loaderUtils2.default.getOptions(this);
  12. if (loaderOptions.include && loaderOptions.include.length) {
  13. var includes = loaderOptions.include.map(function (modPath) {
  14. return 'require(' + _loaderUtils2.default.stringifyRequest(_this, modPath) + ');';
  15. }).join('\n');
  16. var code = [includes, sourceCode].join('\n');
  17. this.callback(null, code, null);
  18. return;
  19. }
  20. this.callback(null, sourceCode, null);
  21. };