rsnext/packages/next/build/babel/loader/index.ts
Balázs Orbán 46e32ae184
feat: copy .env file in standalone mode (#34143)
Ref: #33897

I took a naive approach and simply added `.env` to the files that need to be copied.

Do we want to include `.env.production` as well? Ref: https://nextjs.org/docs/basic-features/environment-variables#loading-environment-variables

(I haven't tested what happens if the file does not exist on copy.)

Other files like `.env.*local` or `.env.{test,development}` don't make sense to copy.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-10 17:48:14 +00:00

56 lines
1.5 KiB
TypeScript

import { Span } from '../../../trace'
import transform from './transform'
import { NextJsLoaderContext } from './types'
async function nextBabelLoader(
this: NextJsLoaderContext,
parentTrace: Span,
inputSource: string,
inputSourceMap: object | null | undefined
) {
const filename = this.resourcePath
const target = this.target
const loaderOptions = parentTrace
.traceChild('get-options')
// @ts-ignore TODO: remove ignore once webpack 5 types are used
.traceFn(() => this.getOptions())
const loaderSpanInner = parentTrace.traceChild('next-babel-turbo-transform')
const { code: transformedSource, map: outputSourceMap } =
loaderSpanInner.traceFn(() =>
transform.call(
this,
inputSource,
inputSourceMap,
loaderOptions,
filename,
target,
loaderSpanInner
)
)
return [transformedSource, outputSourceMap]
}
const nextBabelLoaderOuter = function nextBabelLoaderOuter(
this: NextJsLoaderContext,
inputSource: string,
inputSourceMap: object | null | undefined
) {
const callback = this.async()
const loaderSpan = this.currentTraceSpan.traceChild('next-babel-turbo-loader')
loaderSpan
.traceAsyncFn(() =>
nextBabelLoader.call(this, loaderSpan, inputSource, inputSourceMap)
)
.then(
([transformedSource, outputSourceMap]: any) =>
callback?.(null, transformedSource, outputSourceMap || inputSourceMap),
(err) => {
callback?.(err)
}
)
}
export default nextBabelLoaderOuter