Skip to content
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

Synchronize with current jorgenvatle:vite-bundler release #45

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
322782e
Revert "Use Meteor-compiled version of react-dom"
JorgenVatle Oct 19, 2023
d9ef230
Fix out of scope variables in Info component.
JorgenVatle Oct 19, 2023
e3998c7
Add Vite plugin to import React from Meteor bundle.
JorgenVatle Oct 19, 2023
78f9a94
Merge remote-tracking branch 'origin/release' into release
JorgenVatle Oct 19, 2023
eb95ff7
Refactor Vite-Meteor React bundle plugin to handle an array of user-s…
JorgenVatle Oct 19, 2023
e0770fc
Update Meteor package versions.
JorgenVatle Oct 19, 2023
702cf12
Add utility shell script for managing example apps.
JorgenVatle Oct 19, 2023
3263793
Simplify project build, start and link scripts using example app util…
JorgenVatle Oct 19, 2023
d047985
Add React example app to production build workflow.
JorgenVatle Oct 19, 2023
6028501
Update Vite bundler version in Vue example.
JorgenVatle Oct 19, 2023
ba8bab2
Add JetBrains scopes and file colors to version control.
JorgenVatle Oct 20, 2023
ca9c10c
Tweak file color for meteor-vite package.
JorgenVatle Oct 20, 2023
4886c8c
Add Gitignore to .idea
JorgenVatle Oct 20, 2023
7fcbd77
Ignore unused configurations.
JorgenVatle Oct 20, 2023
b323f3b
Upgrade vite bundler in Svelte example.
JorgenVatle Oct 20, 2023
ce453f2
Rename tsup build watcher environment variable.
JorgenVatle Oct 20, 2023
37fcd9c
Add Svelte example modules.js file to mocks.
JorgenVatle Oct 20, 2023
cd1300d
Add runSetters and runModuleSetters to Parser MethodMap
JorgenVatle Oct 20, 2023
035d604
Declare expected type for RunSetters method.
JorgenVatle Oct 20, 2023
cf06101
Add type declaration for module.runModuleSetters() method.
JorgenVatle Oct 20, 2023
e886f02
Only parse top-level require declarations for MeteorInstall.
JorgenVatle Oct 20, 2023
d7fb793
Extract node type narrowing into separate methods.
JorgenVatle Oct 20, 2023
26acf8f
Clean up type checks in MeteorInstall parser.
JorgenVatle Oct 20, 2023
a305c06
Disable warning for simplified conditions.
JorgenVatle Oct 20, 2023
8b421fb
Use more broad input type for isMeteorInstall() method.
JorgenVatle Oct 20, 2023
79372aa
Add utility types for known string literals and identifiers.
JorgenVatle Oct 20, 2023
0849940
Add Identifier type MeteorInstallObject keys
JorgenVatle Oct 20, 2023
f1068a2
Use prop parser to get meteorInstall object keys.
JorgenVatle Oct 20, 2023
e2a2baa
Emit build result message before exiting in production-build.ts
JorgenVatle Oct 20, 2023
ff6f2c6
Refactor production build worker to separate config and validation st…
JorgenVatle Oct 20, 2023
cfc0e6d
Re-organize code structure in production-build worker.
JorgenVatle Oct 20, 2023
9c8cf50
Throw on error during build in production-build.ts
JorgenVatle Oct 20, 2023
6adc8bd
Use try-catch block for production build IPC interface.
JorgenVatle Oct 20, 2023
9b9d195
Handle undefined importer in useMeteorBundle plugin.
JorgenVatle Oct 20, 2023
4d2c40f
Add missing config file passthrough during production-build.
JorgenVatle Oct 20, 2023
bfbd81d
Attempt to shut down Vite server gracefully on worker shutdown.
JorgenVatle Oct 20, 2023
b3ade8e
Check react example in Readme.
JorgenVatle Oct 20, 2023
fde1854
Merge remote-tracking branch 'Akryum/temp-update-from-fork' into merg…
JorgenVatle Oct 22, 2023
0e54cf9
chore: apply eslint fixes.
JorgenVatle Oct 22, 2023
89660f9
Fix MeteorViteConfig export in vite-connection-handler.ts
JorgenVatle Oct 22, 2023
3ba2ded
Fix variable access before definition in workers.ts
JorgenVatle Oct 22, 2023
2314ce0
Remove unused generic argument in isMeteorIPCMessage.
JorgenVatle Oct 22, 2023
d4b751b
Suppress ESLint warning for non-mutable exports.
JorgenVatle Oct 22, 2023
67ca79f
Add missing throw to ModuleExportsError in parseExportDefault.
JorgenVatle Oct 22, 2023
bed3622
Move prop parser to fix eslint pre-declaration error.
JorgenVatle Oct 22, 2023
0c3c22e
Enable ESLint inspection
JorgenVatle Oct 22, 2023
e5ebf3e
Use unknown type over empty object for vite-server refreshNeeded IPC …
JorgenVatle Oct 22, 2023
2715732
Move listening variable up to suppress eslint pre-declaration warning.
JorgenVatle Oct 22, 2023
481d6cd
Fix eslint errors in vite-server.ts
JorgenVatle Oct 22, 2023
5f99500
Run linter in dedicated workflow.
JorgenVatle Oct 22, 2023
29514aa
Use plain-style scalar for lint workflow.
JorgenVatle Oct 22, 2023
45373ca
Remove linting step from test workflow.
JorgenVatle Oct 22, 2023
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
86 changes: 86 additions & 0 deletions .bin/example-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash

this="$0"
action="$1" # e.g. link, build, start
app="$2" # e.g. vue, svelte


APP_DIR="$PWD/examples/$app"
BUILD_TARGET="$PWD/examples/output/$app"
NPM_LINK_TARGET="$PWD/npm-packages/meteor-vite"
export METEOR_PACKAGE_DIRS="$PWD/packages"
export METEOR_VITE_TSUP_BUILD_WATCHER="true"


# Start a development server
start() {
cd "$APP_DIR" || exit 1
meteor npm start
}

# Install dependencies for dev app
install() {
cd "$APP_DIR" || exit 1
meteor npm i
}

# Build an example app for production
build() {
(link) || exit 1
(cleanOutput) || exit 1

## Disable file watcher for meteor-vite npm package to prevent builds from hanging indefinitely
METEOR_VITE_TSUP_BUILD_WATCHER="false"

cd "$APP_DIR" || exit 1
meteor build "$BUILD_TARGET" --directory
}

# Build then start a production app
launch() {
(build) || exit 1
chmod +w -R "$BUILD_TARGET" # Allow writes to the build, very handy for tinkering with the builds

start:production
}

# Start an already built production app
start:production() {
(production:install) || exit 1

local PRODUCTION_SERVER="$this production:app $app"
local MONGO_SERVER="$this production:mongo $app"

concurrently --names "PROD,DEV" --prefixColors "cyan,dim" "$PRODUCTION_SERVER" "$MONGO_SERVER"
}

cleanOutput() {
rm -rf "$BUILD_TARGET"
}

link() {
cd "$APP_DIR" || exit 1
meteor npm link "$NPM_LINK_TARGET"
}

production:install() {
cd "$BUILD_TARGET/bundle/programs/server" || exit 1
meteor npm install
}

production:mongo() {
start # Just using the meteor dev server for it's reusable mongo server
}

production:app() {
cd "$BUILD_TARGET/bundle" || exit 1;

export PORT=4040
export ROOT_URL=http://localhost:4040
export MONGO_URL=mongodb://127.0.0.1:3001/meteor

meteor node main.js
}

set -x
"$action" || exit 1;
6 changes: 6 additions & 0 deletions .github/workflows/build-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ jobs:
uses: ./.github/workflows/_reuse_.build.yml
with:
name: svelte

react:
name: React
uses: ./.github/workflows/_reuse_.build.yml
with:
name: react
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint
on:
push:
pull_request:
branches:
- main
- release

env:
NPM_PACKAGE_PATH: ./npm-packages/meteor-vite

jobs:
lint:
name: Lint repository
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
- name: Install root dependencies
run: npm ci
- name: Lint code
run: npm run lint
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ jobs:
run: cd "$NPM_PACKAGE_PATH" && npm test
- name: Install root dependencies
run: npm ci
- name: Lint code
run: npm run lint
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules/
output/
.npm/
.idea/
.meteor-vite
examples/*/vite
examples/*/.meteor/local
11 changes: 11 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/fileColors.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/scopes/Meteor_Vite__npm_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/scopes/React__example_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/scopes/Svelte__example_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/scopes/Vite_Bundler__atmosphere_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/scopes/Vue__example_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Use [Vite](https://vitejs.dev) in your Meteor app! ⚡️
- [x] [Vue 3](/examples/vue)
- [Live demo](https://vite-and-vue3.meteorapp.com/)
- [x] [Svelte](/examples/svelte)
- [ ] React
- [x] [React](/examples/react)

## Installation

Expand Down
61 changes: 60 additions & 1 deletion examples/react/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,67 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

/**
* @param npmPackages {string[]}
* @return {import('vite').Plugin}
*/
function useMeteorBundle({
npmPackages = [],
}) {
/**
* @type {{npmPackage: string, chunkPath: string}[]}
*/
const detectedChunks = []
return {
name: 'output-gen',
enforce: 'pre',
resolveId(id, importer, options) {
if (!importer)
return

const npmPackage = npmPackages.find(name => importer.includes(`/${name}.js?`))
if (!npmPackage)
return

const chunk = {
npmPackage,
chunkPath: id.replace(/^.\//, ''),
}

detectedChunks.push(chunk)
console.log({ id, importer, options, chunk })
},
transform(code, id) {
if (!detectedChunks.length)
return

const chunk = detectedChunks.find(({ chunkPath }) => id.includes(`.vite/deps/${chunkPath}`))
if (!chunk)
return

console.log({ transformId: id, chunk })
const exportKey = `require_${chunk.npmPackage.replace(/\//g, '_')}`
return `
var __getOwnPropNames = Object.getOwnPropertyNames;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var ${exportKey} = () => require('${chunk.npmPackage}');
export {
__commonJS,
${exportKey},
}`
},
}
}

export default defineConfig({
plugins: [react()],
plugins: [
react(),
useMeteorBundle({
npmPackages: ['react'],
}),
],

meteor: {
clientEntry: 'imports/vite-entrypoint.jsx',
Expand Down
Loading