1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Remove Typescript helpers in favor of babel helpers (#6087)

There's still a few Typescript helpers in use, but regenerator is added by Babel after this change, as it was already in the bundle it'll drop bundle sizes by quite a bit, eg _app.js becomes half the size.
This commit is contained in:
Tim Neutkens 2019-01-18 22:00:15 +01:00 committed by GitHub
parent 9f08e48d72
commit bbc346869e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 5 deletions

View file

@ -62,7 +62,6 @@
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "9.0.0",
"babel-jest": "23.6.0",
"babel-plugin-transform-define": "1.3.0",
"benchmark": "2.1.4",
"cheerio": "0.22.0",
"chromedriver": "2.42.0",
@ -71,7 +70,6 @@
"eslint-plugin-typescript": "0.14.0",
"express": "4.16.3",
"fkill": "5.1.0",
"flatten": "1.0.2",
"get-port": "3.2.0",
"isomorphic-unfetch": "3.0.0",
"jest-cli": "23.6.0",

View file

@ -32,7 +32,8 @@
},
"taskr": {
"requires": [
"./taskfile-typescript.js"
"./taskfile-typescript.js",
"./taskfile-babel.js"
]
},
"dependencies": {

View file

@ -0,0 +1,23 @@
// taskr babel plugin with Babel 7 support
// https://github.com/lukeed/taskr/pull/305
'use strict'
const transform = require('@babel/core').transform
module.exports = function (task) {
task.plugin('babel', {}, function * (file, opts) {
const options = {
...opts
}
options.filename = file.base
options.plugins = [
require('@babel/plugin-syntax-dynamic-import'),
...(options.plugins || [])
]
options.babelrc = false
options.configFile = false
options.babelrcRoots = false
const output = transform(file.data, options)
file.data = Buffer.from(output.code)
})
}

View file

@ -1,4 +1,22 @@
const notifier = require('node-notifier')
const babelOpts = {
presets: [
['@babel/preset-env', {
modules: 'commonjs',
'targets': {
'browsers': ['IE 11']
}
}]
],
plugins: [
['@babel/plugin-transform-runtime', {
corejs: 2,
helpers: true,
regenerator: true,
useESModules: false
}]
]
}
export async function compile (task) {
await task.parallel(['bin', 'server', 'nextbuild', 'nextbuildstatic', 'pages', 'lib', 'client'])
@ -25,7 +43,7 @@ export async function nextbuild (task, opts) {
}
export async function client (task, opts) {
await task.source(opts.src || 'client/**/*.+(js|ts|tsx)').typescript({module: 'commonjs', target: 'es5'}).target('dist/client')
await task.source(opts.src || 'client/**/*.+(js|ts|tsx)').typescript({module: 'commonjs'}).babel(babelOpts).target('dist/client')
notify('Compiled client files')
}
@ -36,7 +54,7 @@ export async function nextbuildstatic (task, opts) {
}
export async function pages (task, opts) {
await task.source(opts.src || 'pages/**/*.+(js|ts|tsx)').typescript({module: 'commonjs', target: 'es5'}).target('dist/pages')
await task.source(opts.src || 'pages/**/*.+(js|ts|tsx)').typescript({module: 'commonjs'}).babel(babelOpts).target('dist/pages')
}
export async function build (task) {