Skip to content

Commit 4478690

Browse files
committed
1.0.0
1 parent 5e50166 commit 4478690

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed

README.md

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@
44

55
All the features you'd expect and more, from development to production:
66

7-
- 🕶 No "entry points" or "pages" to configure - just `<script type=module src=anything.js>`
8-
- ⛳️ `import "packages"` from npm **_without installation_**
9-
- 📦 Smart bundling and caching for npm dependencies
10-
- 🔄 Hot reloading for modules, Preact components and CSS
11-
- ⚡️ Lightning-fast JSX support that you can debug in the browser
12-
- 💄 Import CSS files and [CSS Modules](https://github.com/css-modules/css-modules) (`*.module.css`)
13-
- 🦄 Static file serving with hot reloading of CSS and images
14-
- 🗜 Highly optimized Rollup-based production output (`wmr build`)
15-
- 🏎 Built-in HTTP2 support in both development and production (`preact serve --http2`)
16-
- 🔧 Supports Rollup plugins, even in development where Rollup isn't used
7+
<font size="5">🔨</font> &nbsp; No "entry points" or "pages" to configure - just `<script type=module src=anything.js>`
8+
<font size="5">🦦</font> &nbsp; `import "packages"` from npm **_without installation_**
9+
<font size="5">📦</font> &nbsp; Smart bundling and caching for npm dependencies
10+
<font size="5">↻</font> &nbsp; Hot reloading for modules, Preact components and CSS
11+
<font size="5">⚡️</font> &nbsp; Lightning-fast JSX support that you can debug in the browser
12+
<font size="5">💄</font> &nbsp; Import CSS files and [CSS Modules](https://github.com/css-modules/css-modules) (`*.module.css`)
13+
<font size="5">📂</font> &nbsp; Static file serving with hot reloading of CSS and images
14+
<font size="5">🗜</font> &nbsp; Highly optimized Rollup-based production output (`wmr build`)
15+
<font size="5">📑</font> &nbsp; Crawls and pre-renders your app's pages to static HTML at build time
16+
<font size="5">🏎</font> &nbsp; Built-in HTTP2 support in both development and production (`wmr serve --http2`)
17+
<font size="5">🔧</font> &nbsp; Supports [Rollup plugins](#configuration-and-plugins), even in development where Rollup isn't used
1718

1819
## Quickstart _(recommended)_
1920

20-
Create a new project in seconds with [create-wmr](https://npm.im/create-wmr): **`npm init wmr your-project-name`**
21+
Create a new project in seconds using [create-wmr](https://npm.im/create-wmr):
2122

23+
<font size="5"><strong><code>npm init wmr your-project-name</code></strong></font>
24+
25+
<p>
2226
<img width="400" src="https://user-images.githubusercontent.com/105127/100917537-4661e100-34a5-11eb-89bd-565b7bc31919.gif">
27+
</p>
2328

2429
> 💁 If you'd like ESLint to be set up for you, add `--eslint` to the command. _Note: this will use 150mb of disk space._
2530
@@ -29,7 +34,7 @@ While it's best to use the quickstart method above, WMR caters to folks who want
2934

3035
There isn't really anything WMR-specific to set up - the steps here are essentially the what you would do to use a simple HTTP server.
3136

32-
1. First, install `wmr` using npm or yarn:
37+
**1.** First, install `wmr` using npm or yarn:
3338

3439
```sh
3540
npm i -D wmr
@@ -39,59 +44,62 @@ yarn add -D wmr
3944

4045
> 🔥 _You can also use `npx wmr` anywhere!_
4146
42-
2. Next you'll want to create an `index.html` file. You can use [this example](https://github.com/preactjs/wmr/blob/master/demo/public/index.html),
43-
but there's nothing special here. To add scripts, make sure to include `type="module"`:
47+
**2.** Next you'll want to create a `public/index.html` file. You can use [this example](https://github.com/preactjs/wmr/blob/master/demo/public/index.html), though there's really nothing special about this HTML file. Just make sure your scripts are ES Modules by including `type="module"`:
4448

4549
```html
4650
<!DOCTYPE html>
4751
<html>
48-
<head>
49-
<link rel="stylesheet" href="/style.css">
50-
</head>
51-
<body>
52-
<script type="module" src="/index.js"></script>
53-
</body>
52+
<head>
53+
<link rel="stylesheet" href="/style.css" />
54+
</head>
55+
<body>
56+
<script type="module" src="/index.js"></script>
57+
</body>
5458
</html>
5559
```
5660

57-
3. To test things out, create that `index.js` file and add a simple Preact component to it:
61+
> 💁 **Why `public/`?** Keeping your code and assets in `public/` prevents files like `node_modules` and `package.json` from being accessed by browsers. It also helps separate your web-facing code from other things like build scripts and output files.
62+
> WMR auto-detects your `public/` directory, or you can specify your own by passing `--public src` to any of the commands.
63+
64+
**3.** To test things out, create that `index.js` file and add a simple Preact component to it:
5865

5966
```js
6067
import { render } from 'preact';
6168

6269
function App() {
63-
return <h1>Hello World!</h1>;
70+
return <h1>Hello World!</h1>;
6471
}
6572

6673
render(<App />, document.body);
6774
```
6875

69-
4. Now we can add some scripts to our `package.json`. There's one for starting the dev server, another to create a production build. A third script serves that production build for easy local testing:
76+
**4.** Now we can add some scripts to our `package.json`. There's one for starting the dev server, another to create a production build. A third script serves that production build for easy local testing:
7077

7178
```json
7279
{
73-
"scripts": {
74-
"start": "wmr",
75-
"build": "wmr build",
76-
"serve": "wmr serve --http2"
77-
}
80+
"scripts": {
81+
"start": "wmr",
82+
"build": "wmr build",
83+
"serve": "wmr serve --http2"
84+
}
7885
}
7986
```
8087

81-
5. You're all set! As an extra step, if you want WMR to pre-render your application to static HTML when building for production, replace `render()` with [preact-iso](https://www.npmjs.com/package/preact-iso):
88+
**5.** You're all set! As an extra step, if you'd like WMR to prerender your application to static HTML during production builds, replace `render()` with [preact-iso](https://www.npmjs.com/package/preact-iso):
8289

8390
```diff
8491
-import { render } from 'preact';
8592
+import hydrate from 'preact-iso/hydrate';
86-
93+
8794
function App() {
8895
return <h1>Hello World!</h1>;
8996
}
90-
97+
9198
-render(<App />, document.body);
9299
+hydrate(<App />);
93100

94101
+export async function prerender(data) {
102+
+ // we use dynamic import to prevent this from being loaded in the browser:
95103
+ return (await import('preact-iso/prerender')).default(<App {...data} />);
96104
+}
97105
```
@@ -106,22 +114,23 @@ You can export a config function, or individual config functions for each of the
106114
import someRollupPlugin from '@rollup/plugin-xyz';
107115

108116
/** @param {import('wmr').Options} config */
109-
export default async function(config) {
110-
if (config.mode === 'build') {
111-
config.plugins.push(
112-
someRollupPlugin()
113-
);
114-
}
115-
116-
if (config.mode === 'serve') {
117-
options.middleware.push(
118-
// add any Polka middleware
119-
(req, res, next) => {
120-
res.setHeader('X-Foo', 'bar');
121-
next();
122-
}
123-
);
124-
}
117+
export default async function (config) {
118+
if (config.mode === 'build') {
119+
config.plugins.push(
120+
// add any Rollup plugins:
121+
someRollupPlugin()
122+
);
123+
}
124+
125+
if (config.mode === 'serve') {
126+
options.middleware.push(
127+
// add any Polka middleware:
128+
function myPolkaMiddleware(req, res, next) {
129+
res.setHeader('X-Foo', 'bar');
130+
next();
131+
}
132+
);
133+
}
125134
}
126135
```
127136

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wmr",
3-
"version": "0.0.12",
3+
"version": "1.0.0",
44
"bin": "wmr.cjs",
55
"type": "module",
66
"scripts": {

0 commit comments

Comments
 (0)