cyansalt / vite-plugin-legacy-swc Goto Github PK
View Code? Open in Web Editor NEWProvides legacy browsers support for the production build with SWC
License: ISC License
Provides legacy browsers support for the production build with SWC
License: ISC License
Hello!
Looking at the plugin implementation, it is set to false, but @vitejs/plugin-legacy binds the value according to the build.minify option. Is there a reason that option is false?
vite-plugin-legacy-swc/src/index.ts
Line 703 in 6a0fc35
Hi! ๐
Firstly, thanks for your work on this project! ๐
Today I used patch-package to patch [email protected]
for the project I'm working on.
It seems like the "types" export is missing, causing issues with typescript when using moduleResolution: "NodeNext"
Here is the diff that solved my problem:
diff --git a/node_modules/vite-plugin-legacy-swc/package.json b/node_modules/vite-plugin-legacy-swc/package.json
index 62cbde3..f35c247 100644
--- a/node_modules/vite-plugin-legacy-swc/package.json
+++ b/node_modules/vite-plugin-legacy-swc/package.json
@@ -8,6 +8,7 @@
"types": "./dist/index.d.ts",
"exports": {
".": {
+ "types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
This issue body was partially generated by patch-package.
Trying to import this legacy plugin like so
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import legacy from "vite-plugin-legacy-swc";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), legacy()],
});
causes the following error:
~/src/vite-project master โ โ
โถ yarn build
yarn run v1.22.19
$ tsc && vite build
failed to load config from /home/bjorn/src/vite-project/vite.config.ts
error during build:
TypeError: legacy is not a function
at file:///home/bjorn/src/vite-project/vite.config.ts.timestamp-1676562433105.mjs:6:22
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async loadConfigFromBundledFile (file:///home/bjorn/src/vite-project/node_modules/vite/dist/node/chunks/dep-3007b26d.js:62302:21)
at async loadConfigFromFile (file:///home/bjorn/src/vite-project/node_modules/vite/dist/node/chunks/dep-3007b26d.js:62187:28)
at async resolveConfig (file:///home/bjorn/src/vite-project/node_modules/vite/dist/node/chunks/dep-3007b26d.js:61808:28)
at async build (file:///home/bjorn/src/vite-project/node_modules/vite/dist/node/chunks/dep-3007b26d.js:44492:20)
at async CAC.<anonymous> (file:///home/bjorn/src/vite-project/node_modules/vite/dist/node/cli.js:813:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
In order to make it work, you have to do this
import legacyPkg from 'vite-plugin-legacy-swc'
// @ts-expect-error the package type definition is wrong
const legacy = legacyPkg.default as typeof legacyPkg
Steps to recreate:
$ yarn create vite
$ # Select React, Typescript + swc
$ yarn add -D vite-plugin-legacy-swc
$ # Edit vite.config.ts to match the first one in this issue
$ yarn build
Node version: v18.12.0
@vitejs/plugin-legacy just launched v5.3, including 3 feat.
Glad to submit a PR. But let's start aligning until vitejs/vite#15788 is solved.
Packaging will generate two sets of codes, one is for modern browsers, and the other is code that is compatible with lower versions. How to set up to generate only one set of code that is compatible with lower versions?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.