Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
meta: use Vite for examples/dev (#3361)
It's a bit hacky, but it works :) We should be getting even more performance when we switch to ESM and stop using JSX in `.js` files.
- Loading branch information
Showing
10 changed files
with
424 additions
and
54 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
.yarn/patches/babel-plugin-transform-commonjs-npm-1.1.6-0007fa2809
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
diff --git a/dist/index.js b/dist/index.js | ||
index 0f9a4b342c75d75309b78a36473fb5c68f7b89b5..57effed56c190a946756d191cb3d390dbc84aee3 100644 | ||
--- a/dist/index.js | ||
+++ b/dist/index.js | ||
@@ -92,18 +92,32 @@ exports.default = helper_plugin_utils_1.declare((api, options) => { | ||
const specifiers = []; | ||
// Convert to named import. | ||
if (core_1.types.isObjectPattern(path.parentPath.node.id)) { | ||
- path.parentPath.node.id.properties.forEach(prop => { | ||
- specifiers.push(core_1.types.importSpecifier(prop.value, prop.key)); | ||
- state.globals.add(prop.value.name); | ||
- }); | ||
- const decl = core_1.types.importDeclaration(specifiers, core_1.types.stringLiteral(str.value)); | ||
- // @ts-ignore | ||
- decl.__replaced = true; | ||
- path.scope.getProgramParent().path.unshiftContainer('body', decl); | ||
- path.parentPath.remove(); | ||
+ if(node.arguments[0].value.startsWith('.') || node.arguments[0].value.startsWith('@uppy/')) { | ||
+ const id = path.scope.generateUidIdentifier(node.arguments[0].value) | ||
+ const destructuring = core_1.types.variableDeclarator(path.parentPath.node.id, id) | ||
+ const decl = core_1.types.importDeclaration([core_1.types.importDefaultSpecifier(id)], core_1.types.stringLiteral(str.value)); | ||
+ // @ts-ignore | ||
+ decl.__replaced = true; | ||
+ path.scope.getProgramParent().path.unshiftContainer('body', decl); | ||
+ path.parentPath.replaceWith(destructuring) | ||
+ } else { | ||
+ path.parentPath.node.id.properties.forEach(prop => { | ||
+ specifiers.push(core_1.types.importSpecifier(prop.value, prop.key)); | ||
+ state.globals.add(prop.value.name); | ||
+ }); | ||
+ const decl = core_1.types.importDeclaration(specifiers, core_1.types.stringLiteral(str.value)); | ||
+ // @ts-ignore | ||
+ decl.__replaced = true; | ||
+ path.scope.getProgramParent().path.unshiftContainer('body', decl); | ||
+ path.parentPath.remove() | ||
+ } | ||
} | ||
+ else if (node.arguments[0].value === 'tus-js-client' && str) { | ||
+ const decl = core_1.types.importDeclaration([core_1.types.importNamespaceSpecifier(path.parentPath.node.id)], core_1.types.stringLiteral(str.value)) | ||
+ path.scope.getProgramParent().path.unshiftContainer('body', decl); | ||
+ path.parentPath.remove() | ||
// Convert to default import. | ||
- else if (str) { | ||
+ } else if (str) { | ||
const { parentPath } = path; | ||
const { left } = parentPath.node; | ||
// @ts-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { fileURLToPath } from 'node:url' | ||
import { transformAsync } from '@babel/core' | ||
|
||
const ROOT = new URL('../../', import.meta.url) | ||
const PACKAGES_ROOT = fileURLToPath(new URL('./packages/', ROOT)) | ||
|
||
// To enable the plugin, it looks like we need to interact with the resolution | ||
// algorithm, but we need to stop afterwards otherwise it messes up somewhere | ||
// else. This hack can be removed when we get rid of JSX inside of .js files. | ||
let counter = 0 | ||
|
||
/** | ||
* @type {import('vite').UserConfig} | ||
*/ | ||
const config = { | ||
build: { | ||
commonjsOptions: { | ||
defaultIsModuleExports: true, | ||
}, | ||
}, | ||
esbuild: { | ||
jsxFactory: 'h', | ||
jsxFragment: 'Fragment', | ||
}, | ||
resolve: { | ||
alias: [ | ||
{ | ||
find: /^uppy\/(.+)$/, | ||
replacement: `${PACKAGES_ROOT}uppy/$1`, | ||
}, | ||
{ | ||
find: /^@uppy\/([^/]+)$/, | ||
replacement: `${PACKAGES_ROOT}@uppy/$1/src/index.js`, | ||
}, | ||
{ | ||
find: /^@uppy\/([^/]+)\/lib\/(.+)$/, | ||
replacement: `${PACKAGES_ROOT}@uppy/$1/src/$2`, | ||
}, | ||
// { | ||
// find: /^@uppy\/([^/]+)\/(.+)$/, | ||
// replacement: PACKAGES_ROOT + "@uppy/$1/src/$2", | ||
// }, | ||
], | ||
}, | ||
plugins: [ | ||
// TODO: remove plugin when we switch to ESM and get rid of JSX inside .js files. | ||
{ | ||
name: 'vite-plugin-jsx-commonjs', | ||
// TODO: remove this hack when we get rid of JSX inside .js files. | ||
enforce: 'pre', | ||
// eslint-disable-next-line consistent-return | ||
resolveId (id) { | ||
if (id.startsWith(PACKAGES_ROOT) && id.endsWith('.js')) { | ||
return id | ||
} | ||
// TODO: remove this hack when we get rid of JSX inside .js files. | ||
if (counter++ < 2) { | ||
return id | ||
} | ||
}, | ||
transform (code, id) { | ||
if (id.startsWith(PACKAGES_ROOT) && id.endsWith('.js')) { | ||
return transformAsync(code, { | ||
plugins: [ | ||
['@babel/plugin-transform-react-jsx', { pragma: 'h' }], | ||
'transform-commonjs', | ||
], | ||
}) | ||
} | ||
return code | ||
}, | ||
}, | ||
], | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.