Skip to content

Commit ef83775

Browse files
pixelasticElPicador
authored andcommitted
feat(serve): Watch and serve all needed files (#91)
Running `npm run serve` will watch for changes in the source files and rebuild all `css` and `js` files accordingly in the `dist` folder. It will also expose the same files on `http://localhost:8080/` (by default, if port `8080` is already taken it will move to an available one). This will let developers use a specific branch/version of docsearch in their projects. Just open a new tab and run `npm run serve` in the docsearch repo, and you'll be able to include the scripts from the running server in your HTML. As files are automatically regenerated on disk whenever a change is detected, you can also `require` files by targeting the `dist` folder.
1 parent 54e7d12 commit ef83775

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ npm run dev
222222
- `npm run build:docs` will create the `./docs/documentation.md` file from the
223223
`README.md` file, to be displayed on the website.
224224
- `npm run build` will run all three previous commands
225+
- `npm run serve` will serve and watch the JavaScript and CSS files on
226+
[http://localhost:8080/](http://localhost:8080/). If port `8080` is already
227+
taken, it will choose an available port. Source files will also be available
228+
and watched in `./dist/`.
225229

226230
### Documentation website
227231

scripts/serve

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
#!/usr/bin/env bash
2-
# Will expose the build version on:
3-
# - http://0.0.0.0:8080/docsearch.css
4-
# - http://0.0.0.0:8080/docsearch.js
2+
# Serves the current build version on a local server available (by default) on
3+
# http://127.0.0.1:8080/docsearch.js and http://127.0.0.1/docsearch.css
4+
#
5+
# This is useful when you want to test the latest docsearch.js version
6+
# (including your own branches) on a specific local project. Just run `npm run
7+
# serve` in the docsearch repository, and link the file in your project.
8+
#
9+
# This works by running webpack in watch mode as well as simply serving the dist
10+
# folder through a local web server.
511

612
npm run build:css
713

8-
# /bundle.js in memory
9-
webpack-dev-server \
14+
# Watch changes and rebuild file if needed
15+
NODE_ENV=production \
16+
webpack \
1017
--config webpack.serve.config.babel.js \
11-
--hot \
12-
--inline \
13-
--no-info & \
14-
# rebuild docsearch.css and docsearch.min.css
18+
-w &
19+
# Serve files
20+
cd dist/cdn && http-server &
21+
# Rebuild css
1522
onchange './src/styles/*.scss' -- npm run build:css & \
1623

1724
wait

0 commit comments

Comments
 (0)