esbuild-glsl
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,3 +0,3 @@ | ||
"use strict";var c=Object.create;var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var n in e)o(t,n,{get:e[n],enumerable:!0})},s=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of p(e))!m.call(t,l)&&l!==n&&o(t,l,{get:()=>e[l],enumerable:!(i=u(e,l))||i.enumerable});return t};var f=(t,e,n)=>(n=t!=null?c(g(t)):{},s(e||!t||!t.__esModule?o(n,"default",{value:t,enumerable:!0}):n,t)),P=t=>s(o({},"__esModule",{value:!0}),t);var w={};d(w,{webglPlugin:()=>b});module.exports=P(w);var a=f(require("fs")),x=()=>(Date.now()*Math.random()).toString(36).slice(0,8),$=`webgl-${x()}`,b=()=>({name:$,setup(t){t.onLoad({filter:/\.glsl$/,namespace:"file"},e=>{let i=a.default.readFileSync(e.path,"utf8").replace(/\/\*.*\*\//gm,"").replace(/\/\/.*/g,"").replace(/ [=+*-/] /g,r=>r.trim()).split(` | ||
`).map(r=>r.trim()).filter(Boolean);return{contents:`export default \`${i[0]} | ||
${i.slice(1).join("")}\``,loader:"ts"}})}});0&&(module.exports={webglPlugin}); | ||
"use strict";var c=Object.create;var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var n in e)o(t,n,{get:e[n],enumerable:!0})},s=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of g(e))!m.call(t,l)&&l!==n&&o(t,l,{get:()=>e[l],enumerable:!(i=u(e,l))||i.enumerable});return t};var f=(t,e,n)=>(n=t!=null?c(p(t)):{},s(e||!t||!t.__esModule?o(n,"default",{value:t,enumerable:!0}):n,t)),P=t=>s(o({},"__esModule",{value:!0}),t);var w={};d(w,{webglPlugin:()=>b});module.exports=P(w);var a=f(require("fs")),x=()=>(Date.now()*Math.random()).toString(36).slice(0,8),$=`webgl-${x()}`,b=()=>({name:$,setup(t){t.onLoad({filter:/\.glsl$/,namespace:"file"},e=>{let i=a.default.readFileSync(e.path,"utf8").replace(/\/\*.*\*\//gm,"").replace(/\/\/.*/g,"").replace(/ ([=+*-/%><&^|]|[=!><+*-/]=|&&|\|\||\^\^) /g,r=>r.trim()).split(` | ||
`).map(r=>r.trim()).filter(Boolean);return{contents:`${i[0]} | ||
${i.slice(1).join("")}`,loader:"text"}})}});0&&(module.exports={webglPlugin}); |
@@ -5,3 +5,3 @@ { | ||
"private": false, | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "ESBuild plugin to load webGL shaders from .glsl files.", | ||
@@ -32,3 +32,3 @@ "license": "MPL-2.0", | ||
"@vitest/coverage-v8": "^1.6.0", | ||
"esbuild": "^0.21.5", | ||
"esbuild": "^0.22.0", | ||
"tsup": "^8.1.0", | ||
@@ -35,0 +35,0 @@ "typescript": "^5.5.2", |
@@ -5,10 +5,27 @@ # Esbuild Plugin Webgl <img src="https://github.com/react18-tools/esbuild-plugin-webgl/blob/main/popper.png?raw=true" style="height: 40px"/> | ||
ESBuild plugin to load webGL shaders from `.glsl` files. | ||
ESBuild plugin to load WebGL shaders from `.glsl` files. | ||
> <img src="https://github.com/react18-tools/esbuild-plugin-webgl/blob/main/popper.png?raw=true" style="height: 20px"/> Please consider starring [this repository](https://github.com/react18-tools/esbuild-plugin-webgl) and sharing it with your friends. | ||
## Overview | ||
This ESBuild plugin streamlines the process of loading WebGL shaders in your JavaScript or TypeScript projects. By allowing you to import GLSL shader files directly into your project, it ensures a seamless development experience for WebGL applications. This approach promotes better separation of concerns by eliminating the need to hard code GLSL shader code into your JS or TS files. Additionally, it compresses the shader code, helping you to deliver a smaller minified bundle for your library. | ||
### Key Features | ||
- **Easy Integration**: Easily integrate GLSL shaders into your ESBuild workflow. | ||
- **TypeScript Support**: Full support for TypeScript, making it easier to work with shaders in a type-safe environment. | ||
- **Lightweight**: Minimal footprint, ensuring your build times remain fast. | ||
- **Flexible Configuration**: Compatible with various build tools and configurations, including `tsup` and standard `esbuild` setups. | ||
## Getting Started | ||
Follow these steps to get started with the ESBuild Plugin WebGL: | ||
### Installation | ||
You can install the plugin using your preferred package manager: | ||
Using `pnpm`: | ||
```bash | ||
@@ -18,3 +35,3 @@ $ pnpm add esbuild-plugin-webgl | ||
**_or_** | ||
Using `npm`: | ||
@@ -25,3 +42,3 @@ ```bash | ||
**_or_** | ||
Using `yarn`: | ||
@@ -32,6 +49,10 @@ ```bash | ||
> If you are using `monorepo` or `workspaces`, you can install this plugin to the root using `-w` or to a specific workspace using `--filter your-package` or `--scope your-package` for `pnpm` or `yarn` workspaces, respectively. | ||
> **Note**: If you are using a monorepo or workspaces, you can install this plugin at the root using the `-w` option or to a specific workspace using `--filter your-package` or `--scope your-package` for `pnpm` or `yarn` workspaces, respectively. | ||
## Use with `tsup` | ||
## Usage | ||
### With `tsup` | ||
To use the plugin with `tsup`, add it to your `tsup.config.ts` or `tsup.config.js` file: | ||
```ts | ||
@@ -42,10 +63,12 @@ // tsup.config.ts or tsup.config.js | ||
export default defineConfig(options => ({ | ||
export default defineConfig((options) => ({ | ||
... | ||
esbuildPlugins:[webglPlugin()] | ||
esbuildPlugins: [webglPlugin()], | ||
})); | ||
``` | ||
## Use with `esbuild` | ||
### With `esbuild` | ||
To use the plugin directly with `esbuild`, include it in your build configuration: | ||
```ts | ||
@@ -55,12 +78,35 @@ import { webglPlugin } from "esbuild-plugin-webgl"; | ||
esbuild.build({ | ||
... | ||
plugins: [webglPlugin()], | ||
... | ||
plugins: [webglPlugin()], | ||
}); | ||
``` | ||
### Example Usage | ||
Here's a quick example of how you can import and use a GLSL shader in your project: | ||
```ts | ||
import vertexShader from "./shaders/vertex.glsl"; | ||
import fragmentShader from "./shaders/fragment.glsl"; | ||
// Initialize WebGL context and use the imported shaders | ||
const gl = canvas.getContext("webgl"); | ||
const vertexShader = gl.createShader(gl.VERTEX_SHADER); | ||
gl.shaderSource(vertexShader, vertexShaderSource); | ||
gl.compileShader(vertexShader); | ||
const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); | ||
gl.shaderSource(fragmentShader, fragmentShaderSource); | ||
gl.compileShader(fragmentShader); | ||
``` | ||
![Alt](https://repobeats.axiom.co/api/embed/a1fadcf8aa3054acff5d430c970af9e61254da5c.svg "Repobeats analytics image") | ||
## Contributing | ||
Contributions are welcome! If you find a bug or have a feature request, please open an issue. For major changes, please open a discussion first to discuss what you would like to change. | ||
## License | ||
This library is licensed under the MPL-2.0 open-source license. | ||
This library is licensed under the MPL-2.0 open-source license. See the [LICENSE](LICENSE) file for more details. | ||
@@ -67,0 +113,0 @@ > <img src="https://github.com/react18-tools/esbuild-plugin-webgl/blob/main/popper.png?raw=true" style="height: 20px"/> Please consider enrolling in [our courses](https://mayank-chaudhari.vercel.app/courses) or [sponsoring](https://github.com/sponsors/mayank1513) our work. |
Sorry, the diff of this file is not supported yet
8552
112