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

How did you build for browser? #39

Open
TaylorHawkes opened this issue Nov 12, 2024 · 2 comments
Open

How did you build for browser? #39

TaylorHawkes opened this issue Nov 12, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@TaylorHawkes
Copy link

TaylorHawkes commented Nov 12, 2024

Describe the Feature

Trying to develop some new features but very difficult to get build for browser working to you have rollup or webpack config that you used available?

Motivation [optional]

No response

Sample Code

No response

Would you like to work on this issue?

None

@TaylorHawkes TaylorHawkes added the enhancement New feature or request label Nov 12, 2024
@eduardoleao052
Copy link
Owner

Screenshot 2024-11-15 at 12 28 08

Adding the script tag provided on the cdnjs website to the HEAD of your HTML file, you can use js-pytorch in any script tag inside your file.
This image serves as an example.
If it's still not working, please let me know!

@eduardoleao052 eduardoleao052 self-assigned this Nov 15, 2024
@TaylorHawkes
Copy link
Author

Thanks Eduardo,
I actually meant the system to build the "js-pytorch-browser.js" file... I was able to get it working using rollup. Here was config I used "rollup.config.js" in case you ever want to integrate a build system for web... (I also I had to move the other.gpu = new GPU(); dependency out of tensor.ts) :
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import polyfillNode from 'rollup-plugin-polyfill-node'; // Use this if you need to polyfill Node modules

export default {
input: 'src/index.ts',
output: {
file: 'dist/js-pytorch-browser.js',
format: 'iife', // Change to appropriate format if needed (e.g., umd)
name: 'JsPytorch',
globals: {
fs: 'null' // Ensures fs is treated as null in the browser
}
},
plugins: [
resolve({
browser: true,
preferBuiltins: false // Important for resolving Node modules to browser versions
}),
commonjs(),
typescript(),
// Uncomment if you need to polyfill Node built-ins:
// polyfillNode()
]
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants