Comments (8)
Fair enough, up to you then. npx
can consume from a somewhat ill-defined cache, so the consequence of not installing it into the project as you would any other tool is that it can use a really old version (if its around) or pull a newer version than the user expects (with breaking changes they might not be aware of). I've personally always been happy with adding even an occasionally-used tool to my package.json
and prefer it to the nebulous npx
behavior, but that's just me.
from microbundle.
Please provide a reproduction.
Some TS module resolutions require you add "types"
your package.json#exports
, i.e.,
{
"main": "./dist/index.js",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"default": "./dist/index.modern.mjs"
},
"module": "./dist/index.module.js",
"unpkg": "./dist/index.umd.js",
"source": "./index.ts",
"types": "./dist/index.d.ts",
}
Edit:
How do I avoid creating a browser build.
You're not. This comes from Rollup, and can be safely ignored, though I have no clue how you're triggering it.
from microbundle.
I will add the explicit "exports.types" as you suggested. If that fails, I will try to create a reproduction.
In the meantime... I noticed that the "test-project" that I use to test my exports had a different tsconfig.json
.
The "test-project" uses "moduleResolution": "Node"
, whereas my "real-project", uses "moduleResolution": "Bundler".
I can't recall why I opted to use Bundler
over ESNext
... 🤔
The "real-project" kind of runs bun build ./functions/some-serverless-fn --outdir ./dist
from where my Appwrite Backend as a Service reads the JS file from. Maybe that's why I did it.
See bun recommendations [here](https://bun.sh/docs/typescript#suggested-compileroptions.
from microbundle.
"moduleResolution": "bundler"
requires exports.types
, yes, see: https://www.typescriptlang.org/tsconfig#moduleResolution
from microbundle.
Bless. Exports types worked. What a god send. Thanks for the prompt response @rschristian!
Question not at all related with microbundle
, maybe you know how to do it.
It's my first time needing to add codegen utilities to a open-sourced package. Right now I am doing a recursive copy of codegen JS files and telling my users to run them like node node_modules/a_huge_path/file.js
, do you happen to know how I could tell them to instead just do:
npx my-package script
? Would it suffice to add the script to the package.json, like a regular project?
from microbundle.
Yay!
As for the second part, package.json#bin
is what you're after. For example:
{
"bin": "./dist/index.js"
}
Packages installed with this entry will be added to node_modules/.bin/
(typically through symlinks) which will allow you to run npx <package>
, executing <package>/dist/index.js
. If you wanted to offer it through a different name (like if it's namespaced, might be nicer to offer a shorter name), you can do so by making package.json#bin
an object:
{
"bin": {
"short-name": "./dist/index.js"
}
}
This'll allow npx short-name
.
Would it suffice to add the script to the package.json, like a regular project?
Depends a bit on what you want to offer I suppose. Do you want them to install & keep a copy in their project, or just offer a script to do something? npx
is pretty loose here in that it'll run the package if it's already installed in the project, else, it'll pull it straight from NPM to run it. You don't necessarily need to tell users to install it/add it to a package.json if it's going to be more of a one-off or occasional thing.
from microbundle.
Hmm nice. I am creating a migration-tool
for structured database migration management with Appwrite. To ensure "stuff" works as intended and avoid errors from manual procedures, I want the users to be able to generate "empty" migration files, with commands.
So the idea would be something like npx admt new <outdir> <description>
; So I guess it's an occasional thing.
from microbundle.
Thanks so much for the tips! :)
from microbundle.
Related Issues (20)
- Using for of loop adds ~300 bytes of polyfill code HOT 5
- CSS var default `transparent` becomes `#0000` (Version 0.15.1) HOT 4
- Environment variables HOT 3
- Facing difficulty in using my bundled package HOT 2
- inline of dependency leads to failed imports in source HOT 14
- No name was provided for external module 'preact/compat' HOT 2
- Build for React Server Components HOT 7
- Alias are specific only? HOT 2
- Wrong "import" in UMD bundle of UMD package HOT 8
- 打包后的产物 x.moduel.mjs 存在箭头函数,导致IE 无法兼容 HOT 3
- Add `x_google_ignoreList` (Ignore-listing code) support to sourcemaps HOT 9
- update rollup from 2.35.1 (2020-12-14) to at least 3.16.0 (2023-02-17), or ideally latest (4.6.1, 2023-11-30) HOT 12
- Cannot build when importing @sentry/browser HOT 5
- Dymanic imports not working in next.js and webpack applications HOT 2
- How can I include SVGs into my build? HOT 16
- Using React 17 or 18 i get the following error rpt2: options error TS5089: Option 'jsxFactory' cannot be specified when option 'jsx' is 'react-jsx'. HOT 1
- prevent export merge HOT 5
- Microbundle is awesome!
- Error when using file JS built by microbundle "Uncaught ReferenceError: require is not defined" HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microbundle.