Skip to content

Commit 6a61e6c

Browse files
authored
Merge pull request #263 from brunolm/copy-files-public-build
Add example to copy files to public during build
2 parents e94550e + c6e92d0 commit 6a61e6c

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

i18n/en-US/components/Examples.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ posts:
3737
- title: "Using Nullstack to build a personal Portfolio on GitHub"
3838
href: "/examples/using-nullstack-to-build-a-personal-portfolio-on-github"
3939
description: "Nullstack can be used to build a personal Portfolio on GitHub."
40+
- title: "Copying static files to the public folder on build"
41+
href: "/examples/copying-static-files-to-the-public-folder-on-build"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: "Copying static files to the public folder on build"
3+
description: "Copy static files to the public folder, like schema files, css, js and other files that comes with certain packages"
4+
---
5+
6+
To copy static files to the public folder you need to create a custom webpack override.
7+
8+
In order to modify the webpack config that comes in the Nullstack bundle, you can create a `webpack.config.js` as mentioned in the documentation ["How to customize Webpack"](/how-to-customize-webpack).
9+
10+
```js
11+
// webpack.config.js
12+
const [server, client] = require("nullstack/webpack.config");
13+
14+
const fse = require("fs-extra");
15+
16+
class CopyFiles {
17+
apply() {
18+
fse.copySync("node_modules/swagger-ui-dist", "public/api-docs", {
19+
overwrite: true,
20+
});
21+
}
22+
}
23+
24+
function customServer(...args) {
25+
const config = server(...args);
26+
config.plugins.push(new CopyFiles());
27+
return config;
28+
}
29+
30+
module.exports = [customServer, client];
31+
```
32+
33+
In case you need to serve these files, you can use `context.server` to create a route and `express.static` to point to the files you want to serve.
34+
35+
```js
36+
// server.js
37+
context.server.use(
38+
"/api-docs/",
39+
express.static(path.join(__dirname, "..", "public/api-docs"))
40+
);
41+
// ...
42+
```

i18n/pt-BR/components/Examples.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ posts:
1919
- title: "Using Nullstack to build a personal Portfolio on GitHub"
2020
href: "/examples/using-nullstack-to-build-a-personal-portfolio-on-github"
2121
description: "Nullstack can be used to build a personal Portfolio on GitHub."
22+
- title: "Copiando arquivos estaticos para pasta public durante o build"
23+
href: "/examples/copiando-arquivos-estaticos-para-pasta-public-durante-o-build"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: "Copiando arquivos estaticos para pasta public durante o build"
3+
description: "Copiando arquivos estaticos para pasta public, como arquivos de schema, css, js e outros arquivos que vem com certos pacotes"
4+
---
5+
6+
To copy static files to the public folder you need to create a custom webpack override.
7+
8+
In order to modify the webpack config that comes in the Nullstack bundle, you can create a `webpack.config.js` as mentioned in the documentation ["How to customize Webpack"](/how-to-customize-webpack).
9+
10+
```js
11+
// webpack.config.js
12+
const [server, client] = require("nullstack/webpack.config");
13+
14+
const fse = require("fs-extra");
15+
16+
class CopyFiles {
17+
apply() {
18+
fse.copySync("node_modules/swagger-ui-dist", "public/api-docs", {
19+
overwrite: true,
20+
});
21+
}
22+
}
23+
24+
function customServer(...args) {
25+
const config = server(...args);
26+
config.plugins.push(new CopyFiles());
27+
return config;
28+
}
29+
30+
module.exports = [customServer, client];
31+
```
32+
33+
In case you need to serve these files, you can use `context.server` to create a route and `express.static` to point to the files you want to serve.
34+
35+
```js
36+
// server.js
37+
context.server.use(
38+
"/api-docs/",
39+
express.static(path.join(__dirname, "..", "public/api-docs"))
40+
);
41+
// ...
42+
```

0 commit comments

Comments
 (0)