Skip to content

Commit 4bf4af0

Browse files
committed
feat: support assets
1 parent 8297269 commit 4bf4af0

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "component-docs",
3+
"version": "0.0.0-development",
34
"description": "Documentation for React components",
45
"scripts": {
56
"build": "babel -sd dist/ src/ --copy-files",
@@ -29,6 +30,7 @@
2930
"dedent": "^0.7.0",
3031
"express": "^4.16.2",
3132
"extract-text-webpack-plugin": "^3.0.2",
33+
"fs-extra": "^5.0.0",
3234
"history": "^4.7.2",
3335
"ignore-styles": "^5.0.1",
3436
"illuminate-js": "^0.3.0",

src/configureWebpack.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ export default ({ root, entry, output, production }: Options) => ({
8080
options: babelrc,
8181
},
8282
},
83-
{
84-
test: /\.(bmp|gif|jpg|jpeg|png|svg|webp|ttf|otf)$/,
85-
use: { loader: 'url-loader', options: { limit: 25000 } },
86-
},
8783
{
8884
test: /\.css$/,
8985
use: production

src/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import express from 'express';
55
import webpack from 'webpack';
66
import devMiddleware from 'webpack-dev-middleware';
77
import hotMiddleware from 'webpack-hot-middleware';
8-
import fs from 'fs';
8+
import fs from 'fs-extra';
99
import path from 'path';
1010
import watch from 'node-watch';
1111
import buildEntry from './buildEntry';
@@ -48,6 +48,7 @@ const stringifyData = data => `module.exports = [
4848
]`;
4949

5050
export function build({
51+
assets,
5152
pages: getPages,
5253
output,
5354
layout = require.resolve('./templates/Layout'),
@@ -61,6 +62,7 @@ export function build({
6162

6263
fs.writeFileSync(path.join(output, 'app.src.js'), buildEntry({ layout }));
6364
fs.writeFileSync(path.join(output, 'app.data.js'), stringifyData(data));
65+
fs.copySync(assets, path.join(output, 'assets'));
6466

6567
buildEntry({ layout });
6668
buildPageInfo(data).forEach(info => {
@@ -90,6 +92,7 @@ export function build({
9092
}
9193

9294
export function serve({
95+
assets,
9396
pages: getPages,
9497
output,
9598
port = 3031,
@@ -137,6 +140,10 @@ export function serve({
137140

138141
const app = express();
139142

143+
app.get('/assets/*', (req, res) => {
144+
res.sendFile(path.join(assets, req.path.replace(/^\/assets\//, '')));
145+
});
146+
140147
app.get('*', (req, res, next) => {
141148
const page = req.path.slice(1).replace(/\.html$/, '');
142149

src/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type Page =
1010
export type Separator = { type: 'separator' };
1111

1212
export type Options = {
13+
assets: string,
1314
pages: Array<Page | Separator> | (() => Array<Page | Separator>),
1415
output: string,
1516
port?: number,

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,14 @@ fs-extra@^4.0.2:
26832683
jsonfile "^4.0.0"
26842684
universalify "^0.1.0"
26852685

2686+
fs-extra@^5.0.0:
2687+
version "5.0.0"
2688+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
2689+
dependencies:
2690+
graceful-fs "^4.1.2"
2691+
jsonfile "^4.0.0"
2692+
universalify "^0.1.0"
2693+
26862694
fs-readdir-recursive@^1.0.0:
26872695
version "1.0.0"
26882696
resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.0.0.tgz#8cd1745c8b4f8a29c8caec392476921ba195f560"

0 commit comments

Comments
 (0)