Babel upgrades

This commit is contained in:
Sam Potts 2018-09-25 22:25:04 +10:00
parent 3331d9d01d
commit cc55092ca6
2 changed files with 37 additions and 63 deletions

View File

@ -88,29 +88,26 @@ const sizeOptions = { showFiles: true, gzip: true };
const browsers = ['> 1%']; const browsers = ['> 1%'];
// Babel config // Babel config
const babelrc = { const babelrc = (polyfill = false) => ({
presets: [ presets: [
[ [
'env', '@babel/preset-env',
{ {
targets: { targets: {
browsers, browsers,
}, },
useBuiltIns: true, useBuiltIns: polyfill ? 'usage' : false,
modules: false, modules: false,
}, },
], ],
], ],
plugins: ['external-helpers'],
babelrc: false, babelrc: false,
exclude: 'node_modules/**', exclude: 'node_modules/**',
}; });
// Clean out /dist // Clean out /dist
gulp.task('clean', () => { gulp.task('clean', () => {
const dirs = [paths.plyr.output, paths.demo.output].map(dir => const dirs = [paths.plyr.output, paths.demo.output].map(dir => path.join(dir, '**/*'));
path.join(dir, '**/*'),
);
// Don't delete the mp4 // Don't delete the mp4
dirs.push(`!${path.join(paths.plyr.output, '**/*.mp4')}`); dirs.push(`!${path.join(paths.plyr.output, '**/*.mp4')}`);
@ -124,6 +121,7 @@ const build = {
const name = `js:${key}`; const name = `js:${key}`;
tasks.js.push(name); tasks.js.push(name);
const { output } = paths[bundle]; const { output } = paths[bundle];
const polyfill = name.includes('polyfilled');
return gulp.task(name, () => return gulp.task(name, () =>
gulp gulp
@ -133,11 +131,7 @@ const build = {
.pipe( .pipe(
rollup( rollup(
{ {
plugins: [ plugins: [resolve(), commonjs(), babel(babelrc(polyfill))],
resolve(),
commonjs(),
babel(babelrc),
],
}, },
options, options,
), ),
@ -244,10 +238,7 @@ try {
} }
// If deployment is setup // If deployment is setup
if ( if (Object.keys(credentials).includes('aws') && Object.keys(credentials).includes('fastly')) {
Object.keys(credentials).includes('aws') &&
Object.keys(credentials).includes('fastly')
) {
const { version } = pkg; const { version } = pkg;
const { aws, fastly } = credentials; const { aws, fastly } = credentials;
@ -269,8 +260,7 @@ if (
demo: { demo: {
uploadPath: branch.current === branch.develop ? 'beta/' : null, uploadPath: branch.current === branch.develop ? 'beta/' : null,
headers: { headers: {
'Cache-Control': 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
'no-cache, no-store, must-revalidate, max-age=0',
Vary: 'Accept-Encoding', Vary: 'Accept-Encoding',
}, },
}, },
@ -279,8 +269,7 @@ if (
headers: { headers: {
// http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect // http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect
'x-amz-website-redirect-location': `/${ver}/${filename}`, 'x-amz-website-redirect-location': `/${ver}/${filename}`,
'Cache-Control': 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
'no-cache, no-store, must-revalidate, max-age=0',
}, },
}; };
}, },
@ -303,11 +292,7 @@ if (
const allowed = [branch.master, branch.develop]; const allowed = [branch.master, branch.develop];
if (!allowed.includes(branch.current)) { if (!allowed.includes(branch.current)) {
console.error( console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
`Must be on ${allowed.join(', ')} to publish! (current: ${
branch.current
})`,
);
return false; return false;
} }
@ -349,8 +334,7 @@ if (
.pipe( .pipe(
replace( replace(
/sourceMappingURL=([\w-?.]+)/, /sourceMappingURL=([\w-?.]+)/,
(match, p1) => (match, p1) => `sourceMappingURL=${p1.replace(minSuffix, '')}`,
`sourceMappingURL=${p1.replace(minSuffix, '')}`,
), ),
) )
.pipe( .pipe(
@ -368,27 +352,30 @@ if (
gulp.task('purge', () => { gulp.task('purge', () => {
const list = []; const list = [];
return gulp.src(paths.upload).pipe( return gulp
through.obj((file, enc, cb) => { .src(paths.upload)
const filename = file.path.split('/').pop(); .pipe(
list.push(`${versionPath}/${filename}`); through.obj((file, enc, cb) => {
cb(null); const filename = file.path.split('/').pop();
}), list.push(`${versionPath}/${filename}`);
).on('end', () => { cb(null);
const purge = new FastlyPurge(fastly.token); }),
)
.on('end', () => {
const purge = new FastlyPurge(fastly.token);
list.forEach(url => { list.forEach(url => {
console.log(`Purging ${url}...`); console.log(`Purging ${url}...`);
purge.url(url, (error, result) => { purge.url(url, (error, result) => {
if (error) { if (error) {
console.log(error); console.log(error);
} else if (result) { } else if (result) {
console.log(result); console.log(result);
} }
});
}); });
}); });
});
}); });
// Publish to demo bucket // Publish to demo bucket
@ -400,8 +387,7 @@ if (
console.log(`Uploading '${version}' demo to ${aws.demo.domain}...`); console.log(`Uploading '${version}' demo to ${aws.demo.domain}...`);
// Replace versioned files in readme.md // Replace versioned files in readme.md
gulp gulp.src([`${root}/readme.md`])
.src([`${root}/readme.md`])
.pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`)) .pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`))
.pipe(gulp.dest(root)); .pipe(gulp.dest(root));
@ -415,8 +401,7 @@ if (
pages.push(error); pages.push(error);
} }
gulp gulp.src(pages)
.src(pages)
.pipe(replace(localPath, versionPath)) .pipe(replace(localPath, versionPath))
.pipe(s3(aws.demo, options.demo)); .pipe(s3(aws.demo, options.demo));
@ -468,16 +453,6 @@ if (
// Do everything // Do everything
gulp.task('deploy', () => gulp.task('deploy', () =>
run( run('version', tasks.clean, tasks.js, tasks.sass, tasks.sprite, 'cdn', 'purge', 'demo', 'open'),
'version',
tasks.clean,
tasks.js,
tasks.sass,
tasks.sprite,
'cdn',
'purge',
'demo',
'open',
),
); );
} }

View File

@ -37,8 +37,7 @@
"devDependencies": { "devDependencies": {
"babel-core": "^6.26.3", "babel-core": "^6.26.3",
"babel-eslint": "^9.0.0", "babel-eslint": "^9.0.0",
"babel-plugin-external-helpers": "^6.22.0", "@babel/preset-env": "^7.1.0",
"babel-preset-env": "^1.7.0",
"del": "^3.0.0", "del": "^3.0.0",
"eslint": "^5.6.0", "eslint": "^5.6.0",
"eslint-config-airbnb-base": "^13.1.0", "eslint-config-airbnb-base": "^13.1.0",
@ -84,7 +83,7 @@
"through2": "^2.0.3" "through2": "^2.0.3"
}, },
"dependencies": { "dependencies": {
"babel-polyfill": "^6.26.0", "core-js": "^2.5.7",
"custom-event-polyfill": "^1.0.6", "custom-event-polyfill": "^1.0.6",
"loadjs": "^3.5.4", "loadjs": "^3.5.4",
"raven-js": "^3.27.0", "raven-js": "^3.27.0",