|
| 1 | +# How Do I Use stylesheets with SAFE? |
| 2 | +If you wish to use your own CSS or SASS stylesheets with SAFE apps, you can embed either through webpack. The template already includes all required NPM packages you may need, so you will only need to configure webpack to reference your stylesheet and include in the outputs. |
| 3 | + |
| 4 | +## Adding the Stylesheet |
| 5 | +First, create a CSS file in the `src/Client` folder of your solution e.g `style.css`. |
| 6 | + |
| 7 | +> The same approach can be taken for `.scss` files. |
| 8 | +
|
| 9 | +## Configuring WebPack |
| 10 | + |
| 11 | +### I'm using the Standard Template |
| 12 | +#### 1. Link to the stylesheet |
| 13 | + |
| 14 | +Inside the `webpack.config.js` file, add the following variable to the `CONFIG` object, which points to the style file you created previously. |
| 15 | +```javascript |
| 16 | +cssEntry: './src/Client/style.css', |
| 17 | +``` |
| 18 | + |
| 19 | +#### 2. Embed CSS into outputs |
| 20 | + Find the `entry` field in the `module.exports` object at the bottom of the file, and replace it with the following: |
| 21 | +```javascript |
| 22 | +entry: isProduction ? { |
| 23 | + app: [resolve(CONFIG.fsharpEntry), resolve(CONFIG.cssEntry)] |
| 24 | +} : { |
| 25 | + app: resolve(CONFIG.fsharpEntry), |
| 26 | + style: resolve(CONFIG.cssEntry) |
| 27 | +}, |
| 28 | +``` |
| 29 | + |
| 30 | +This combines the css and F# outputs into a single bundle for production, and separately for dev. |
| 31 | + |
| 32 | +### I'm using the Minimal Template |
| 33 | +#### 1. Embed CSS into outputs |
| 34 | +Find the `entry` field in the `module.exports` object at the bottom of the file, and replace it with the following: |
| 35 | +```javascript |
| 36 | +entry: { |
| 37 | + app: [ |
| 38 | + resolve('./src/Client/Client.fsproj'), |
| 39 | + resolve('./src/Client/style.css') |
| 40 | + ] |
| 41 | +}, |
| 42 | +``` |
| 43 | + |
| 44 | +## There you have it! |
| 45 | +You can now style your app by writing to the `style.css` file. |
0 commit comments