-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
Expose compiler object responsible for compiling the preact application #88
Conversation
@developit did you manage to find some time to look at this PR? It would be great to have some sort of extendability built into this project |
Not yet, no. Hopefully someone else can review before me! |
src/compiler.js
Outdated
import webpackConfig from './lib/webpack-config'; | ||
import runWebpack, { showStats } from './lib/run-webpack'; | ||
|
||
class Compiler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious about everyone's opinions on this, but I wondered if this could have been done more directly via a closure + exported object (just a POJO factory). If everyone is good with classes I don't have a strong opinion here, just it's the first class into this codebase that isn't specifically for Webpack, so I thought I'd ask :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Can anyone make an opinion?)
The implementation looks awesome, but as a personal choice, I'd prefer non-class approaches 👍
I guess it depends on the project... are classes used in preact-cli
?
If so, it could be good to keep consistency with pojo/factory approach 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah maybe a pojo is a better idea, I'll convert it!
|
||
return { | ||
async clean() { | ||
let dest = resolve(env.cwd || process.cwd(), env.dest || 'build'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In retrospective this could have been config.output.path
- if this lands before #56 I'll change it there
Is this still relevant with the ssr-bundle being produced now? |
given that there has been no activity I'm gonna close this we're working towards modularising the cli which will also export the config |
Why was this closed? |
@Download You can require the It's the same approach the CLI is using internally to produce the "prerendered" outputs -- except that you can do it at runtime. I have a full example with this approach & am using it on a couple sites: https://github.com/lukeed/preact-cli-ssr |
Thanks @lukeed an example is always best! I will check out your repo. |
As mentioned by #70, I started creating a reusable compiler instance responsible for building or watching a preact application. The commands are now using this compiler to generate their output. The compiler is exposed as main entry so one can use it in their own project like this;
I guess this can be seen as a first step in exposing an api to built upon; like exposing the prerender functionality to render compiled preact strings in a node.js app, replacing the dev server with dev middleware so you can mount the preact-cli on your own server, etc.