Skip to content

Commit 79d41d6

Browse files
committed
Add docs about Webpack Encore.
1 parent 8f11613 commit 79d41d6

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

source/documentation/basic-project.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,69 @@ generating the site.
8181
With this option passed, `{{ site.url }}/about` will now be generated as
8282
`http://my.dev.host/blog-skelton/output_dev/about` instead of `/about`.
8383

84+
## CSS and JavaScript
85+
86+
It is best practice to combine all your CSS files and all your JavaScript files
87+
into single files. That way they are simple to include in your templates and
88+
create less overhead for the browser loading the page. The recommended way to
89+
combine assets is with Symfony's
90+
[Webpack Encore](https://symfony.com/doc/current/frontend.html).
91+
92+
The [Blog Skeleton](https://github.com/sculpin/sculpin-blog-skeleton) project
93+
uses Encore to manage assets. If you're setting up your project with Sculpin
94+
directly, not using the skeleton, install Encore using the
95+
[setup instructions](https://symfony.com/doc/current/frontend/encore/installation.html).
96+
97+
The rest of this section assumes that you are using Encore, with a
98+
configuration like
99+
[in the skeleton](https://github.com/sculpin/sculpin-blog-skeleton/blob/master/webpack.config.js).
100+
101+
Put your CSS and JS assets in the directory `source/assets/` as shown.
102+
103+
|-- source/
104+
`-- assets/
105+
|-- css/
106+
| `-- app.css
107+
`-- js/
108+
`-- app.js
109+
110+
The app's main CSS file should be `source/assets/css/app.css`.
111+
You can add more CSS files in the same directory if necessary and require them
112+
in your JavaScript files to use them.
113+
114+
Encore can also support Sass, and the Blog Skeleton is set up to use it. See
115+
the relevant
116+
[Encore docs](https://symfony.com/doc/current/frontend/encore/simple-example.html#using-sass-less-stylus)
117+
for more details.
118+
119+
The app's main JavaScript file is `source/assets/js/app.js`. Make sure that it
120+
is added in the `webpack.config.js` configuration file. You can add further
121+
JavaScript files and require them in `app.js`, and `require` other libraries as
122+
necessary.
123+
124+
Build the assets using the command:
125+
126+
yarn encore dev --watch
127+
128+
Encore will then compile all the CSS into the `build/app.css` file and all the
129+
JavaScript, including library code, into the `build/app.js` file.
130+
131+
Include the stylesheet link and script tag in your templates (in `_views/`):
132+
133+
```html
134+
<head>
135+
<link rel="stylesheet" href="{{ site.url }}/build/app.css">
136+
</head>
137+
```
138+
139+
```html
140+
<body>
141+
(all your other content)
142+
143+
<script src="{{ site.url }}/build/runtime.js"></script>
144+
</body>
145+
```
146+
84147
## Environments
85148

86149
Sculpin knows the `dev` and `prod` environment. They allow you to have

0 commit comments

Comments
 (0)