mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
Updated swc plugin
This commit is contained in:
parent
b13fb6af53
commit
fcba5e9996
@ -2,21 +2,19 @@
|
||||
// https://github.com/lukeed/taskr/pull/305
|
||||
|
||||
const path = require('path')
|
||||
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const transform = require('@swc/core').transform
|
||||
|
||||
module.exports = function (task) {
|
||||
// eslint-disable-next-line require-yield
|
||||
task.plugin(
|
||||
'swc',
|
||||
{},
|
||||
function* (file, serverOrClient, { stripExtension, dev, outDir = 'dist', baseUrl = '' } = {}) {
|
||||
function* (
|
||||
file,
|
||||
{ server = true, stripExtension, dev, outDir = 'dist', baseUrl = '' } = {}
|
||||
) {
|
||||
// Don't compile .d.ts
|
||||
if (file.base.endsWith('.d.ts')) return
|
||||
|
||||
const isClient = serverOrClient === 'client'
|
||||
|
||||
const swcClientOptions = {
|
||||
module: {
|
||||
type: 'es6',
|
||||
@ -24,7 +22,6 @@ module.exports = function (task) {
|
||||
},
|
||||
jsc: {
|
||||
loose: true,
|
||||
|
||||
target: 'es2016',
|
||||
parser: {
|
||||
syntax: 'typescript',
|
||||
@ -42,7 +39,6 @@ module.exports = function (task) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const swcServerOptions = {
|
||||
module: {
|
||||
type: 'es6',
|
||||
@ -50,12 +46,11 @@ module.exports = function (task) {
|
||||
},
|
||||
env: {
|
||||
targets: {
|
||||
node: '12.0.0',
|
||||
node: '14.0.0',
|
||||
},
|
||||
},
|
||||
jsc: {
|
||||
loose: true,
|
||||
|
||||
parser: {
|
||||
syntax: 'typescript',
|
||||
dynamicImport: true,
|
||||
@ -73,7 +68,7 @@ module.exports = function (task) {
|
||||
},
|
||||
}
|
||||
|
||||
const swcOptions = isClient ? swcClientOptions : swcServerOptions
|
||||
const swcOptions = server ? swcServerOptions : swcClientOptions
|
||||
|
||||
// Using `outDir` and `baseUrl` build a relative path from `outDir` to
|
||||
// the `baseUrl` path for source maps
|
||||
@ -81,16 +76,15 @@ module.exports = function (task) {
|
||||
const basePath = path.join(__dirname, baseUrl)
|
||||
const relativeFilePath = path.relative(basePath, filePath)
|
||||
const fullFilePath = path.join(__dirname, filePath)
|
||||
const distFilePath = path.dirname(path.join(__dirname, outDir, relativeFilePath))
|
||||
|
||||
const distFilePath = path.dirname(
|
||||
path.join(__dirname, outDir, relativeFilePath)
|
||||
)
|
||||
const options = {
|
||||
filename: filePath,
|
||||
sourceMaps: true,
|
||||
sourceFileName: path.relative(distFilePath, fullFilePath),
|
||||
|
||||
...swcOptions,
|
||||
}
|
||||
|
||||
const output = yield transform(file.data.toString('utf-8'), options)
|
||||
const ext = path.extname(file.base)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
export async function build(task, opts) {
|
||||
await task
|
||||
.source('src/**/*.+(ts|tsx|js)')
|
||||
.swc('server', { dev: opts.dev, outDir: 'dist', baseUrl: 'src' })
|
||||
.swc({ dev: opts.dev, outDir: 'dist', baseUrl: 'src' })
|
||||
.target('dist')
|
||||
.source('src/**/*.+(json|cjs)')
|
||||
.target('dist')
|
||||
|
Loading…
x
Reference in New Issue
Block a user