I am currently migrating an old Firefox extension and want to use the es2017 features.
The dependencies:
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"babel-preset-es2017": "^6.24.1",
"eslint": "^4.19.0",
"gulp": "^4.0.0",
"web-ext": "^2.5.0",
"web-ext-types": "^2.0.1",
"webpack": "^4.1.1",
"webpack-stream": "^4.0.2"
}
My first test file:
export class Test {
async hello(param) {
console.debug('Test', browser);
return `Hello ${param}, how are you?`;
}
}
My second test file:
import { Test } from './Test';
browser.runtime.onStartup.addListener((a, b, c, d) => {
console.debug('Arguments:', a, b, c, d);
const test = new Test();
test.hello('World').then((result) => {
console.debug('Result:', result);
});
});
My gulpfile.babel.js:
import gulp from 'gulp';
import webpack from 'webpack';
import webpackStream from 'webpack-stream';
const backgroundJS = (done) => {
gulp.src(paths.src.js.background)
.pipe(webpackStream(require('./webpack.config.js')), webpack)
.pipe(rename('background.js'))
.pipe(gulp.dest(paths.dist.firefox + '/js'));
done();
};
My webpack.config.js:
module.exports = {
output: {
filename: 'bundle.js',
},
module: {
rules: [{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
query: {
presets: ['es2017']
}
}]
}
};
The result in the background.js does not contain any es2017 code...
() = > {} is converted into function form
classes are replaced by something very ugly
and also the new `` String is not there any more...
What am I doing wrong?