-
Notifications
You must be signed in to change notification settings - Fork 77
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
Programmatic usage? #20
Comments
micro-dev is a development CLI. For programmatic use, take advantage of the micro package. |
@leo I think the doubt is more about using That mean if you use |
The advantages of micro-dev can only be provided over the CLI. micro-dev is only meant to be used as a CLI in development. If you want its advantages, you need to use its CLI. There is no way we can provide this programmatically in a proper way. |
This is not clear. If I use micro in a programmatic way, there should be a way to launch micro-dev from cli and still support that way of launching the application |
@leo Is there a way to use micro-dev from CLI while using micro programmatically? Currently receiving this error:
I tried @sergiodxa 's recommendation of appending the filename (ie. |
I know this is kind of an off-topic question. But I'm wondering why you guys want to use micro programmatically in the first place? I'm just trying to think about this issue another way around. |
@tungv Good question. Why programmatically? What about micro CLI makes it difficult to homogenize builds?
These are by no means hard blockers (I caved yesterday, reverted to non-programmatic build and specialized build for micro), but it's definitely frustrating to not be able to use micro-dev programmatically. If that's a requirement, why not just use something like Express? A few soft reasons (in order of high-low weighted relevance)
(PS. I see you contributed to hot reloading so thanks for that <3 ) |
You can use
With npm scripts I don't see how this is an issue, you can also use |
I'm not sure I understand the relevance of Having said that, given that I do need to specialize the build for micro, the port tip is helpful. Thank you, @sergiodxa |
Sounds like there's a lack of concrete use cases in this issue, so I'd like to throw in mine. I currently use {
"main": "dist/index.js",
"scripts": {
"start": "micro",
"build": "tsc",
"dev": "ts-node --typeCheck node_modules/.bin/micro-dev src/index.ts",
"postinstall": "npm run build"
},
"dependencies": {
"micro": "^9.1.4"
},
"devDependencies": {
"@types/micro": "^7.3.1",
"@types/node": "9.4.7",
"micro-dev": "^2.2.1",
"ts-node": "^5.0.1",
"typescript": "^2.7.2"
}
} I've also been testing a version that simply uses {
"main": "index.ts",
"scripts": {
"start": "ts-node node_modules/.bin/micro",
"dev": "ts-node --typeCheck node_modules/.bin/micro-dev"
}
} Being able to require a module before running the app might make this a bit cleaner, something like // script/dev.ts
import microDev from "micro-dev"
import app from ".."
const server = microDev(app)
server.listen(3000) This is similar to the issue pointed out in vercel/micro#337. I hope this is helpful — something to keep in mind as you build out the micro ecosystem! |
My use-case is I'm using websockets as per the micro examples. |
I can definitely echo the websockets usecase—need to pass the server instance to socket.io so need to use micro programmatically. |
So I was making something similar work with tape, which doesn't have built in support for typescript/babel/etc. One of the workarounds to work with typescript (the others include
Here I'm running a typescript file (types, imports, es7 syntax, etc) with sucrase, and passing args (port) to micro-dev, and it all seems to work as it should. Versions used:
Hopefully that helps someone! Can confirm it's soooooooo much faster and concise than a separate Everybody else gave a use case, mine is that I run barebones mock APIs for my frontend typescript projects. I write my mock data in typescript so I can catch missing fields/typos, which means i can't import my mocks directly into micro without some sort of transpilation. Hence, this. |
I need to use micro programatically, i.e.
require('micro')
.Is there any counterpart for this in micro-dev?
The text was updated successfully, but these errors were encountered: