"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _path = _interopRequireDefault(require("path"));

var _webpackSources = require("webpack-sources");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

class SourceMapHookPlugin {
  apply(compiler) {
    compiler.hooks.emit.tap('SourceMapHookPlugin', compilation => {
      Object.keys(compilation.assets).forEach(filename => {
        if (/\.js$/g.test(filename) && !/(\.map.|tp\/)/g.test(filename)) {
          let source = compilation.assets[filename].source();

          let {
            name
          } = _path.default.parse(filename);

          let src = source;

          if (!/(i18n-chunk\/)/g.test(filename)) {
            src = `${source}\n//# sourceMappingURL=../../js/${name}.js.map`;
            compilation.assets[filename.replace(/js\//g, 'smap/js/')] = new _webpackSources.RawSource(src);
          } else {
            compilation.assets[filename.replace(/i18n-chunk\//g, 'smap/i18n-chunk/')] = new _webpackSources.RawSource(src);
          }
        }
      });
    });
  }

}

var _default = SourceMapHookPlugin;
exports.default = _default;