I have an external NPM dependency that uses Object.assign. I want to use Babel, to assure compatibility with old browsers, either transforming Object.assign via helper or substituting it using another method, but it is not working.
PS: I can use a polyfill at the top of the code, i want to avoid this since it is a library ( https://babeljs.io/docs/plugins/transform-object-assign/ )
The dependency is : https://github.com/krux/postscribe via var postscribe = require('postscribe');
my .babelrc conf:
{
"presets": [
["env", {
"targets": {
"browsers": ["Android 4", "iOS 7"]
}
}]
],
"plugins": ["transform-object-assign"]
}
Gulp conf:
gulp.task('adtag', function () {
// set up the browserify instance on a task basis
var b = browserify({
entries: './src/adtag/main.js',
debug: true
}).transform(babelify)
return b.bundle()
.pipe(source('smaatoAdTag.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init({
loadMaps: true
}))
// Add transformation tasks to the pipeline here.
.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/adtag/'));
});
Is there any way to substitute Object.assign if is in a dependency and not in the main code?
Check out the docs for babelify
You could use :
browserify().transform("babelify", {
global: true,
ignore: /\/node_modules\/(?!postscribe\/)/
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.