-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vite Plugin - Watch Workspace (#1154)
* move plugin and add docs * Remove references and add dep * Comments * Fix package name * package-lock + add missing index.ts * add header * Make it work for tsx. Ignore dist folders when using * Fix dependencies * add CJS build command and tsconfig * Make JS default for switch statements * Extend wait for provider image and try to debug on fail * Enclose bash statement in brackets * package-lock.json * package-lock.json
- Loading branch information
Showing
13 changed files
with
487 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -15,6 +15,9 @@ | |
}, | ||
{ | ||
"path": "../../dev/config" | ||
}, | ||
{ | ||
"path": "../../dev/vite-plugin-watch-workspace" | ||
} | ||
] | ||
} |
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,52 @@ | ||
# Vite Plugin Watch Workspace | ||
|
||
Vite Plugin Watch Workspace is a Vite plugin that watches for changes in local dependencies in a monorepo and rebuilds | ||
them when they change. | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @prosopo/vite-plugin-watch-workspace | ||
``` | ||
|
||
## Usage | ||
|
||
Add the plugin to your Vite config: | ||
|
||
```typescript | ||
import { defineConfig } from 'vite' | ||
import { VitePluginWatchWorkspace } from '@prosopo/vite-plugin-watch-workspace' | ||
|
||
export default defineConfig(async function ({ command, mode }) { | ||
return { | ||
plugins: [ | ||
VitePluginWatchWorkspace({ | ||
workspaceRoot: '/path/to/your/workspace', | ||
currentPackage: '/path/to/your/current/package', | ||
format: 'esm', // or 'cjs' | ||
fileTypes: ['ts', 'tsx', 'js', 'jsx'], // optional - file types to watch. default is ['ts', 'tsx'] | ||
ignorePaths: ['node_modules', 'dist'], // optional - globs to ignore | ||
}), | ||
], | ||
} | ||
}) | ||
``` | ||
|
||
#### Options | ||
|
||
- `workspaceRoot` - The root of your monorepo. | ||
- `currentPackage` - The path to the package that is currently being built. Can be a path or a glob. | ||
- `format` - The module format to use. Can be `'esm'` or `'cjs'`. | ||
- `fileTypes` - An array of file types to watch. Optional. Default is `['ts', 'tsx']`. | ||
- `ignorePaths` - An array of globs to ignore. Optional but it is recommended to add a wildcard to ignore your dist | ||
folders, e.g. `**/dist/**`. | ||
|
||
## How it works | ||
|
||
The plugin takes your `workspaceRoot` and searches for packages by reading the `workspaces` field in your workspace | ||
root `package.json`. It then searches for files in the packages that match the `fileTypes` you provided and adds the | ||
files to Vite's watch list. When one of the discovered files changes, the plugin loads the tsconfig associated with it | ||
and builds the file using esbuild. | ||
|
||
See [this article](https://prosopo.io/articles/using-vite-to-rebuild-local-dependencies-in-an-npm-workspace) for more | ||
details. |
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,52 @@ | ||
{ | ||
"name": "@prosopo/vite-plugin-watch-workspace", | ||
"version": "0.3.38", | ||
"description": "Vite plugin for watching and rebuilding external files", | ||
"main": "./dist/index.js", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/cjs/index.cjs" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "echo \"No test specified\"", | ||
"clean": "tsc --build --clean", | ||
"build": "tsc --build --verbose", | ||
"build:cjs": "npx vite --config vite.cjs.config.ts build", | ||
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore", | ||
"eslint:fix": "npm run eslint -- --fix", | ||
"prettier": "npx prettier . --check --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore", | ||
"prettier:fix": "npm run prettier -- --write", | ||
"lint": "npm run eslint && npm run prettier", | ||
"lint:fix": "npm run eslint:fix && npm run prettier:fix" | ||
}, | ||
"engines": { | ||
"node": ">=18", | ||
"npm": ">=9" | ||
}, | ||
"author": "Prosopo Limited", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"debug": "^4.3.4", | ||
"vite": "^5.1.7" | ||
}, | ||
"devDependencies": { | ||
"@types/debug": "^4.1.12", | ||
"tslib": "2.6.2", | ||
"typescript": "5.1.6" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/prosopo/captcha.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/prosopo/captcha/issues" | ||
}, | ||
"homepage": "https://github.com/prosopo/captcha/blob/main/dev/vite-plugin-watch-workspace/README.md", | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"sideEffects": false | ||
} |
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,14 @@ | ||
// Copyright 2021-2024 Prosopo (UK) Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
export * from './vite-plugin-watch-workspace.js' |
Oops, something went wrong.