GeezerVison is showing github.com — Add example to copy files to public during build · nullstack/nullstack.github.io@c6e92d0
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: i18n/en-US/components/Examples.yml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 37 | 37 | - title: "Using Nullstack to build a personal Portfolio on GitHub" | 38 | 38 | href: "/examples/using-nullstack-to-build-a-personal-portfolio-on-github" | 39 | 39 | 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" |
Collapse file Copy file name to clipboard +42Lines changed: 42 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +``` |
Collapse file Copy file name to clipboardExpand all lines: i18n/pt-BR/components/Examples.yml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 | - title: "Using Nullstack to build a personal Portfolio on GitHub" | 20 | 20 | href: "/examples/using-nullstack-to-build-a-personal-portfolio-on-github" | 21 | 21 | 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" |
Collapse file Copy file name to clipboard +42Lines changed: 42 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +``` |
|