|
| 1 | +# Integrating with Backend Framework |
| 2 | + |
| 3 | +If you are building a purely-static app (one that is deployed separately from the backend API), then you probably don't even need to edit `config/index.js`. However, if you want to integrate this template with an existing backend framework, e.g. Rails/Django/Laravel, which comes with their own project structures, you can edit `config/index.js` to directly generate front-end assets into your backend project. |
| 4 | + |
| 5 | +Let's take a look at the default `config/index.js`: |
| 6 | + |
| 7 | +``` js |
| 8 | +var path = require('path') |
| 9 | + |
| 10 | +module.exports = { |
| 11 | + build: { |
| 12 | + index: path.resolve(__dirname, 'dist/index.html'), |
| 13 | + assetsRoot: path.resolve(__dirname, 'dist'), |
| 14 | + assetsSubDirectory: 'static', |
| 15 | + assetsPublicPath: '/', |
| 16 | + productionSourceMap: true |
| 17 | + }, |
| 18 | + dev: { |
| 19 | + port: 8080, |
| 20 | + proxyTable: {} |
| 21 | + } |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +Inside the `build` section, we have the following options: |
| 26 | + |
| 27 | +### `build.index` |
| 28 | + |
| 29 | +> Must be an absolute path on your local file system. |
| 30 | +
|
| 31 | +This is where the `index.html` (with injected asset URLs) will be generated. |
| 32 | + |
| 33 | +If you are using this template with a backend-framework, you can edit `index.html` accordingly and point this path to a view file rendered by your backend app, e.g. `app/views/layouts/application.html.erb` for a Rails app, or `resources/views/index.blade.php` for a Laravel app. |
| 34 | + |
| 35 | +### `build.assetsRoot` |
| 36 | + |
| 37 | +> Must be an absolute path on your local file system. |
| 38 | +
|
| 39 | +This should point to the root directory that contains all the static assets for your app. For example, `public/` for both Rails/Laravel. |
| 40 | + |
| 41 | +### `build.assetsSubDirectory` |
| 42 | + |
| 43 | +Nest webpack-generated assets under this directory in `build.assetsRoot`, so that they are not mixed with other files you may have in `build.assetsRoot`. For example, if `build.assetsRoot` is `/path/to/dist`, and `build.assetsSubDirectory` is `static`, then all Webpack assets will be generated in `path/to/dist/static`. |
| 44 | + |
| 45 | +This directory will be cleaned before each build, so it should only contain assets generated by the build. |
| 46 | + |
| 47 | +Files inside `static/` will be copied into this directory as-is during build. This means if you change this prefix, all your absolute URLs referencing files in `static/` will also need to be changed. See [Handling Static Assets](static.md) for more details. |
| 48 | + |
| 49 | +### `build.assetsPublicPath` |
| 50 | + |
| 51 | +This should be the URL path where your `build.assetsRoot` will be served from over HTTP. In most cases, this will be root (`/`). Only change this if your backend framework serves static assets with a path prefix. Internally, this is passed to Webpack as `output.publicPath`. |
| 52 | + |
| 53 | +### `build.productionSourceMap` |
| 54 | + |
| 55 | +Whether to generate source maps for production build. |
| 56 | + |
| 57 | +### `dev.port` |
| 58 | + |
| 59 | +Specify the port for the dev server to listen to. |
| 60 | + |
| 61 | +### `dev.proxyTable` |
| 62 | + |
| 63 | +Define proxy rules for the dev server. See [API Proxying During Development](proxy.md) for more details. |
0 commit comments