Skip to content

Instantly share code, notes, and snippets.

@simon04
Created February 28, 2018 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simon04/ea3fc9fc757e69d22297b941adb2fa6f to your computer and use it in GitHub Desktop.
Save simon04/ea3fc9fc757e69d22297b941adb2fa6f to your computer and use it in GitHub Desktop.
Minimal buble-loader supporting webpack 4
/* eslint-env node */
const buble = require('buble');
const loaderUtils = require('loader-utils');
const path = require('path');
module.exports = function BubleLoader(source) {
this.cacheable && this.cacheable();
const options = Object.assign({transforms: {modules: false}}, loaderUtils.getOptions(this));
const transformed = buble.transform(source, options);
transformed.map.file = this.resourcePath;
transformed.map.sources[0] = path.relative(process.cwd(), this.resourcePath);
transformed.map.sourceRoot = process.cwd();
this.callback(null, transformed.code, transformed.map);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment