framework icon indicating copy to clipboard operation
framework copied to clipboard

add support for functional `build.transpile` with vite builder

Open belomx opened this issue 3 years ago • 5 comments

Environment

https://codesandbox.io/s/amazing-minsky-nwzxcr?file=/nuxt.config.js

Reproduction

In the "nuxt.config.js" define the build transpile like:

import { defineNuxtConfig } from "nuxt";

export default defineNuxtConfig({ build: { transpile: [({ isDev }) => isDev && "lodash"] } });

Then execute "npm run build"

Describe the bug

The nuxt build is returns the error in logs section. And lodash is not transpiled.

Additional context

The functionality work properly when the nuxt.config is done in typescript ("nuxt.config.ts").

Config from nuxt documentation. https://nuxtjs.org/docs/configuration-glossary/configuration-build/#transpile

Logs

WARN  [SSR] Error transforming /sandbox/node_modules/nuxt/dist/app/entry: filename.split is not a function

  at normalizePath (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:11471:21)
  at getMatcherString (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:11476:16)
  at Object.test (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:11495:33)
  at result (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:11511:25)
  at node_modules/vite/dist/node/chunks/dep-0fc8e132.js:38123:38
  at node_modules/vite/dist/node/chunks/dep-0fc8e132.js:38139:41
  at shouldExternalizeForSSR (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:38066:12)
  at TransformContext.transform (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:40368:34)
  at async Object.transform (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:35579:30)
  at async loadAndTransform (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:39888:29)

belomx avatar Aug 29 '22 01:08 belomx

build.transpile only supports RegExp + strings in Vite. (The function is used for webpack builder only.)

Do you think it's worth adding support for it to vite builder too @pi0? I think it could be useful as someone might want to transpile in server/client context only.

danielroe avatar Aug 30 '22 14:08 danielroe

Yes, we added it to Nuxt 2 for webpack too (main usecase was a transpile for nuxt/http module only on server) makes sense to support function entries for transpile accepting env for vite too (universally) 👍🏼

pi0 avatar Aug 30 '22 14:08 pi0

@danielroe @pi0 I'd be happy to help out with this one. Would you mind pointing me in the right direction? What directories/files would be a good starting point?

jmorel88 avatar Sep 20 '22 13:09 jmorel88

We likely need to move it from https://github.com/nuxt/framework/blob/09c42fd886f1a35f7cd8f400711cd889876828ad/packages/vite/src/vite.ts#L43 to https://github.com/nuxt/framework/blob/5855ba4684e36eb1e785f377d034277f008bc92a/packages/vite/src/server.ts#L50 and https://github.com/nuxt/framework/blob/720da64b1208756d81ea4f8e651e8089f73c180f/packages/vite/src/client.ts#L42.

danielroe avatar Sep 20 '22 13:09 danielroe