Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Symfony Webpack Encore instead of Assetic or Component Manager #63

Merged
merged 2 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/app/config/sculpin_site_*.yml
/app/logs/*
/output_*/
/source/components/
/node_modules/
/source/build/
s3.conf
/vendor/
/vendor/
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@ A very basic Sculpin based blog supporting the following features:
Install
-------

This application uses [Symfony's Webpack Encore](https://symfony.com/doc/current/frontend.html)
to manage CSS, JavaScript and image assets. First install the JS dependencies:

```bash
$ yarn install
```

Then install the PHP dependencies (Sculpin):

```bash
$ composer install
```

Build
-----

php vendor/bin/sculpin generate --watch --server

Your newly generated clone of sculpin-blog-skeleton is now
accessible at `http://localhost:8000/`.
First run Encore, to compile the assets in `source/assets/` into `source/build/`:

Component Management
--------------------
If you wish to install components via composer and have them automatically installed into your source directory you will need the following configuration options to your composer.json file.
```bash
$ yarn encore dev --watch
```

- component-dir: The directory you wish the components to be installed
- components: An array of component names to be installed
Then generate the site with Sculpin:

```bash
$ php vendor/bin/sculpin generate --watch --server
```
"config": {
"component-dir": "source/components",
"components": [
"components/bootstrap",
"components/jquery",
"components/highlightjs"
]
}
```

The component manager will introspect these values to determine what it needs to copy into your source directory on `composer install`.

Your newly generated clone of sculpin-blog-skeleton is now
accessible at `http://localhost:8000/`.


Previewing Development Builds
-----------------------------
Expand Down
39 changes: 0 additions & 39 deletions component-manager.php

This file was deleted.

24 changes: 1 addition & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,6 @@
}
],
"require": {
"sculpin/sculpin": "^3.0@dev",
"components/bootstrap": "^4.1",
"components/jquery": "^3.1",
"components/highlightjs": "^9.7"
},
"config": {
"component-dir": "source/components",
"components": [
"components/bootstrap",
"components/jquery",
"components/highlightjs"
]
},
"scripts": {
"post-install-cmd": [
"ComponentManager\\ComponentManager::postComposerInstall"
],
"post-update-cmd": [
"ComponentManager\\ComponentManager::postComposerInstall"
]
},
"autoload": {
"classmap": ["component-manager.php"]
"sculpin/sculpin": "^3.0@dev"
}
}
148 changes: 1 addition & 147 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dependencies": {
"@symfony/webpack-encore": "^0.24.0",
"bootstrap": "^4.3.1",
"highlightjs": "^9.12.0",
"jquery": "^3.3.1",
"node-sass": "^4.11.0",
"sass-loader": "^7.0.1",
"popper.js": "^1.14.7"
}
}
44 changes: 19 additions & 25 deletions source/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,28 @@
{% block head_meta %}
<meta name="robots" content="noindex, follow">
{% endblock %}
<link href="{{ site.url }}/components/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="{{ site.url }}/css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="{{ site.url }}/build/app.css">

<link rel="apple-touch-startup-image" href="{{ site.url }}/images/jackson/2048x2048.png">
<link rel="apple-touch-startup-image" href="{{ site.url }}/build/2048x2048.png">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="shortcut icon" sizes="76x76" href="{{ site.url }}/images/jackson/76x76.png">
<link rel="shortcut icon" sizes="120x120" href="{{ site.url }}/images/jackson/120x120.png">
<link rel="shortcut icon" sizes="128x128" href="{{ site.url }}/images/jackson/128x128.png">
<link rel="shortcut icon" sizes="152x152" href="{{ site.url }}/images/jackson/152x152.png">
<link rel="shortcut icon" sizes="196x196" href="{{ site.url }}/images/jackson/196x196.png">
<link rel="shortcut icon" sizes="512x512" href="{{ site.url }}/images/jackson/512x512.png">
<link rel="shortcut icon" sizes="1024x1024" href="{{ site.url }}/images/jackson/1024x1024.png">
<link rel="shortcut icon" sizes="2048x2048" href="{{ site.url }}/images/jackson/2048x2048.png">
<link rel="apple-touch-icon" sizes="76x76" href="{{ site.url }}/images/jackson/76x76.png">
<link rel="apple-touch-icon" sizes="120x120" href="{{ site.url }}/images/jackson/120x120.png">
<link rel="apple-touch-icon" sizes="128x128" href="{{ site.url }}/images/jackson/128x128.png">
<link rel="apple-touch-icon" sizes="152x152" href="{{ site.url }}/images/jackson/152x152.png">
<link rel="apple-touch-icon" sizes="196x196" href="{{ site.url }}/images/jackson/196x196.png">
<link rel="apple-touch-icon" sizes="512x512" href="{{ site.url }}/images/jackson/512x512.png">
<link rel="apple-touch-icon" sizes="1024x1024" href="{{ site.url }}/images/jackson/1024x1024.png">
<link rel="apple-touch-icon" sizes="2048x2048" href="{{ site.url }}/images/jackson/2048x2048.png">
<link rel="shortcut icon" sizes="76x76" href="{{ site.url }}/build/jackson/76x76.png">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to move the images to build, or could we keep them in the old location? this could be annoying for people who customized their templates. does encore do something with the images?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, all it does is copy them into the build/assets directory. I can move them back to how they were but personally I find it neater to have css + js + images all in the assets folder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I prefer to have different folders for css, js, and images because putting everything in one tends to get messy over time. If this could be configurable that would be even better imho, giving flexibility to everyone setting up how they like it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see the point of having "images" that are basically icons and stuff that is referenced from the css in the same main folder as the css itself. content images is a different topic.

i don't think there is any configuration needed - encore copies them when they are in asset, otherwise the template needs to reference the original path. and having a configuration injected into the template feels too indirect to me.

what if we call that folder "icons" instead of "images" but keep it in assets? would that help to be more clear what it is meant for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, when I said "css + js + images all in the assets folder," I meant that there would be separate folders for css, js, and images, all within the assets folder. (Which is how the project is set up in this PR.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folders that Encore copies to and from are already configured within the webpack.config.js file, see: https://github.com/sculpin/sculpin-blog-skeleton/blob/2f26a9ce05aedd5db40817e7197948ebe066da3b/webpack.config.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the images in question are really only icons, I think it's a good compromise to rename the folder 'icons' in this example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folders that Encore copies to and from are already configured within the webpack.config.js file, see: /webpack.config.js@2f26a9c

Ah ok great! Cause if for some reason my images path changes in blog posts all paths on the site and external references would have to be updated. But looking at that I can change that to my liking and don't have to worry about it 👍

<link rel="shortcut icon" sizes="120x120" href="{{ site.url }}/build/jackson/120x120.png">
<link rel="shortcut icon" sizes="128x128" href="{{ site.url }}/build/jackson/128x128.png">
<link rel="shortcut icon" sizes="152x152" href="{{ site.url }}/build/jackson/152x152.png">
<link rel="shortcut icon" sizes="196x196" href="{{ site.url }}/build/jackson/196x196.png">
<link rel="shortcut icon" sizes="512x512" href="{{ site.url }}/build/jackson/512x512.png">
<link rel="shortcut icon" sizes="1024x1024" href="{{ site.url }}/build/jackson/1024x1024.png">
<link rel="shortcut icon" sizes="2048x2048" href="{{ site.url }}/build/jackson/2048x2048.png">
<link rel="apple-touch-icon" sizes="76x76" href="{{ site.url }}/build/jackson/76x76.png">
<link rel="apple-touch-icon" sizes="120x120" href="{{ site.url }}/build/jackson/120x120.png">
<link rel="apple-touch-icon" sizes="128x128" href="{{ site.url }}/build/jackson/128x128.png">
<link rel="apple-touch-icon" sizes="152x152" href="{{ site.url }}/build/jackson/152x152.png">
<link rel="apple-touch-icon" sizes="196x196" href="{{ site.url }}/build/jackson/196x196.png">
<link rel="apple-touch-icon" sizes="512x512" href="{{ site.url }}/build/jackson/512x512.png">
<link rel="apple-touch-icon" sizes="1024x1024" href="{{ site.url }}/build/jackson/1024x1024.png">
<link rel="apple-touch-icon" sizes="2048x2048" href="{{ site.url }}/build/jackson/2048x2048.png">

<link rel="stylesheet" href="{{ site.url }}/components/highlightjs/styles/github.css" />
<link rel="alternate" type="application/atom+xml" href="{{ site.url }}/atom.xml" title="{{ site.title }} activity feed" />
{% block head_styles %}
{% endblock %}
Expand Down Expand Up @@ -85,9 +83,7 @@
<span class="text-muted">&copy; {{ "now"|date("Y") }} {{ site.title }}</span>
</footer>

<script src="{{ site.url }}/components/jquery/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="{{ site.url }}/components/bootstrap/js/bootstrap.min.js"></script>
<script src="{{ site.url }}/build/app.js"></script>
bellisk marked this conversation as resolved.
Show resolved Hide resolved
{% block scripts %}
{% endblock %}

Expand All @@ -103,8 +99,6 @@
ga('send', 'pageview');
</script>
{% endif %}
<script src="{{ site.url }}/components/highlightjs/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

{% block scripts_after %}
{% endblock %}
Expand Down
3 changes: 3 additions & 0 deletions source/css/style.css → source/assets/css/app.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@import "../../../node_modules/bootstrap/scss/bootstrap";
@import "../../../node_modules/highlightjs/styles/github.css";

small {
display: block;
color: #888;
Expand Down
7 changes: 7 additions & 0 deletions source/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require('../css/app.scss');

require('jquery')
require('bootstrap')
var hljs = require('highlightjs')

hljs.initHighlightingOnLoad();
Loading