Skip to content

Add support for subpath polyfills #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ jobs:
- uses: ./.github/actions/install-dependencies
- run: pnpm build:core
- run: pnpm build:shims
- run: pnpm -r test
- run: pnpm test:unit
- run: pnpm test:build
typecheck:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export default defineConfig({
// Override the default polyfills for specific modules.
overrides: {
// Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it.
fs: 'memfs',
'fs': 'memfs',
// Subpaths can be specified as well.
'path/posix': 'path-browserify',
},
// Whether to polyfill `node:` protocol imports.
protocolImports: true,
Expand Down
12 changes: 12 additions & 0 deletions examples/solid/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Example (Solid)</title>
</head>
<body>
<div id="solid-app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions examples/solid/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "module",
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"solid-js": "^1.8.7"
},
"devDependencies": {
"vite": "^5.0.2",
"vite-plugin-node-polyfills": "workspace:*",
"vite-plugin-solid": "^2.8.0"
}
}
4 changes: 4 additions & 0 deletions examples/solid/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line unicorn/prefer-node-protocol
import { join } from 'path/posix'

document.querySelector('#solid-app')!.textContent = join('foo', 'bar')
18 changes: 18 additions & 0 deletions examples/solid/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import solid from 'vite-plugin-solid'

export default defineConfig({
optimizeDeps: {
force: true,
},
plugins: [
nodePolyfills({
overrides: {
'path/posix': 'path-browserify',
},
}),
// comment/uncomment it:
solid(),
],
})
8 changes: 8 additions & 0 deletions examples/vue/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { nodePolyfills } from 'vite-plugin-node-polyfills'

// https://vitejs.dev/config/
export default defineConfig({
build: {
lib: {
entry: './src/main.ts',
fileName: 'index',
formats: ['es', 'cjs'],
},
minify: false,
},
plugins: [
nodePolyfills(),
vue(),
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@
"test": "run-p test:build test:error-repros test:unit",
"test:build": "run-p test:build:*",
"test:build:react": "pnpm -C ./examples/react run build",
"test:build:solid": "pnpm -C ./examples/solid run build",
"test:build:vanilla": "pnpm -C ./examples/vanilla run build",
"test:build:vue": "pnpm -C ./examples/vue run build",
"test:dev:react": "pnpm -C ./examples/react run dev",
"test:dev:solid": "pnpm -C ./examples/solid run dev",
"test:dev:vanilla": "pnpm -C ./examples/vanilla run dev",
"test:dev:vue": "pnpm -C ./examples/vue run dev",
"test:error-repros": "run-p test:error-repros:*",
Expand All @@ -95,10 +97,14 @@
},
"dependencies": {
"@rollup/plugin-inject": "^5.0.5",
"node-stdlib-browser": "^1.2.0"
"browser-resolve": "^2.0.0",
"node-stdlib-browser": "^1.2.0",
"pkg-dir": "^8.0.0",
"resolve-esm": "^2.0.3"
},
"devDependencies": {
"@playwright/test": "^1.40.1",
"@types/browser-resolve": "^2.0.4",
"@types/node": "^18.18.8",
"buffer": "6.0.3",
"esbuild": "^0.19.8",
Expand Down
Loading
Loading