-
Notifications
You must be signed in to change notification settings - Fork 50
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
Switch to esbuild #79
Comments
We need asynchronous Wasm loading. We need to check if it supports that. UPD: it does. |
Webpack is having some issues now so I think it's time to switch |
Well, esbuild might not be a viable choice. It's ability to load WASM has some limitations, and attempting to use it results in:
|
What about vite? These are the wasm plugins that I found: |
Another alternative, which is recommended by vites docs https://github.com/Menci/vite-plugin-wasm. |
If #400 gets done, this won't be an issue anymore. |
Meanwhile, for people that don't wanna wait for CTL to upgrade to Purescript 0.15, using Vite(which uses esbuild & rollup under the hood) which support TLA via plugins, you're able to import CTL builds You'll need to use these plugins I've managed to cut back build times by more than 80-90% in most cases If you know what you're doing with Nix and would like to open a PR to move CTL to Vite but can't manage to get Vite working with purescript's output, I'd be more than happy to help out |
I managed to get CTL working with purs-nix, as a dependency. Purs-nix uses esbuild to bundle it, but I'm struggling with the wasm:
@ngua @Banou26 did you get the loader working? What do you mean by An esbuild plugin is the recommended solution, but nix esbuild just have the CLI, It seems that I'll need to make a derivation to bundle the project with the wasm plugin loaded, even so it will not solve TLA issues 🤔 |
I tried to use this bundle script in the Scaffold project output (from purescript compiler): #!/usr/bin/env node
// bundle.mjs
import { build } from 'esbuild';
import { NodeGlobalsPolyfillPlugin as nodeGlobals } from '@esbuild-plugins/node-globals-polyfill';
import { NodeModulesPolyfillPlugin as nodeModules } from '@esbuild-plugins/node-modules-polyfill';
import wasm from 'esbuild-plugin-wat';
build({
entryPoints: ['result/Main/index.js'],
bundle: true,
outfile: 'index.js',
define: {
BROWSER_RUNTIME: "true",
},
plugins: [nodeGlobals(), nodeModules(), wasm()],
}); It throws in the browser:
I looked at this part of the code, probably relates to the wasm loader. I don't know anything about wasm, so I am leaving it here, maybe someone might find it useful. |
Just to add to my comment #79 (comment), and #79 (comment) Vite wont work until #400 gets done, because the only compatible commonjs plugin move imports to top-level, skipping As far as I know, currently, the only option to bundle CTL remains webpack. |
I am pretty sure this isn't true, Vite doesn't need any third party plugins to load CJS and is able to use both ESM's(True) and CJS's(Fake) TLA. Here's my vite config if you wanna try for yourself (you can replace import { defineConfig } from 'vite'
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
import rollupNodePolyFill from 'rollup-plugin-node-polyfills'
import wasm from "vite-plugin-wasm"
export default defineConfig({
resolve: {
alias: {
util: 'rollup-plugin-node-polyfills/polyfills/util',
sys: 'util',
events: 'rollup-plugin-node-polyfills/polyfills/events',
stream: 'rollup-plugin-node-polyfills/polyfills/stream',
path: 'rollup-plugin-node-polyfills/polyfills/path',
querystring: 'rollup-plugin-node-polyfills/polyfills/qs',
punycode: 'rollup-plugin-node-polyfills/polyfills/punycode',
url: 'rollup-plugin-node-polyfills/polyfills/url',
string_decoder: 'rollup-plugin-node-polyfills/polyfills/string-decoder',
http: 'rollup-plugin-node-polyfills/polyfills/http',
https: 'rollup-plugin-node-polyfills/polyfills/http',
os: 'rollup-plugin-node-polyfills/polyfills/os',
assert: 'rollup-plugin-node-polyfills/polyfills/assert',
constants: 'rollup-plugin-node-polyfills/polyfills/constants',
_stream_duplex:
'rollup-plugin-node-polyfills/polyfills/readable-stream/duplex',
_stream_passthrough:
'rollup-plugin-node-polyfills/polyfills/readable-stream/passthrough',
_stream_readable:
'rollup-plugin-node-polyfills/polyfills/readable-stream/readable',
_stream_writable:
'rollup-plugin-node-polyfills/polyfills/readable-stream/writable',
_stream_transform:
'rollup-plugin-node-polyfills/polyfills/readable-stream/transform',
timers: 'rollup-plugin-node-polyfills/polyfills/timers',
console: 'rollup-plugin-node-polyfills/polyfills/console',
vm: 'rollup-plugin-node-polyfills/polyfills/vm',
zlib: 'rollup-plugin-node-polyfills/polyfills/zlib',
tty: 'rollup-plugin-node-polyfills/polyfills/tty',
domain: 'rollup-plugin-node-polyfills/polyfills/domain'
}
},
define: {
BROWSER_RUNTIME: true,
process: {}
},
build: {
target: 'esnext',
commonjsOptions: {
include: [/my-ctl-project/, /node_modules/],
transformMixedEsModules: true
},
rollupOptions: {
external: ['rollup-plugin-node-polyfills', 'util']
}
},
optimizeDeps: {
include: ['my-ctl-project'],
esbuildOptions: {
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
define: {}
}),
NodeModulesPolyfillPlugin()
]
}
},
plugins: [
wasm(),
rollupNodePolyFill()
],
server: {
fs: {
allow: ['..']
}
}
}) |
@Banou26 I have no idea why, but it keeps not transforming CJS modules ( Here is a repro repo: https://github.com/klarkc/test-vite
|
Here's your repo fixed https://github.com/Banou26/cardano-transaction-lib-issue-79 |
I've managed to fix the TLA error with vite by using the exclude option of optimizeDeps, beyond including
Because include was adding everything in |
Implemented here: |
I noticed #62 , and you haven't considered esbuild seemingly.
https://esbuild.github.io/
This is the best bundler I know of.
The text was updated successfully, but these errors were encountered: