[Pkg-javascript-devel] Bug#883553: tentative conversion to webpack/babel build
Paolo Greppi
paolo.greppi at libpf.com
Wed Dec 6 10:19:07 UTC 2017
cat .babelrc
{
"presets": [
"es2015",
],
"plugins": [
"babel-plugin-add-module-exports"
],
"ignore": [
"dist/*.js"
]
}
cat webpack.config.js
'use strict';
var path = require('path');
var config = {
target: 'web',
entry: 'lib/es6-promise.js',
resolve: {
modules: ['/usr/lib/nodejs', '.'],
},
resolveLoader: {
modules: ['/usr/lib/nodejs'],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'es6-promise.js',
libraryTarget: 'umd'
},
module: { rules: [ { use: [ 'babel-loader' ] } ] }
}
module.exports = config;
build with:
webpack --config webpack.config.js
uglifyjs dist/es6-promise.js > dist/es6-promise.min.js
the build succeeds and the resulting binary seems to work; I tested in the browser with this:
<html>
<head></head>
<body>
<script>window.Promise = null;</script>
<script src="es6-promise.js"></script>
<script>
var promise = new Promise(function(resolve, reject) {
var person = prompt("Please enter your name", "Harry Potter");
if (person != null) {
resolve("Stuff worked!");
}
else {
reject("It broke");
}
});
promise.then(function(result) {
console.log(result);
}, function(err) {
console.log(err);
});
</script>
</body>
</html>
this seems to do what upstream's es6-promise-auto does: "Automatically provides/replaces Promise if missing or broken"
Paolo
More information about the Pkg-javascript-devel
mailing list