Skip to content
This repository was archived by the owner on Feb 16, 2021. It is now read-only.

Conversation

@tijsverkoyen
Copy link
Member

Using grunt

We are using grunt to handle a shitload of frontend related tasks, below you
can find all stuff that is done. This is more a guide for you to understand
what is happening.

@todo

  • shouldn't we include the css/js from outside the document root as these
    will be "compiled" with assetic
  • fix deployment
  • fix issue with bootstrap glyphicons-halflings
  • fix issue with jquery.min.map
  • try to find solution for livereload when grunt watch isn't running
  • remove references to my local repo's
  • tag our bundles and update composer.json
  • fix issue with woff2-file

Coffee

We will look into all bundles in the src-folder for all files in the
Resources/assets/coffee-folder, these files will be copied to the
assets/coffee-folder in the root directory. All files will be prefixed with
the lowercased bundlename.

After that the files will be compiled into web/assets/js.

As this will generate seperate files for each file we will combine them through
assetic. See How to use Assetic for asset management
for the full documentation but basically:

{% javascripts
    'assets/js/frameworkcorebundle.framework.data.js'
    'assets/js/frameworkcorebundle.framework.locale.js'
    'assets/js/frameworkcorebundle.framework.form.js'
    'assets/js/frameworkcorebundle.framework.js'
    'assets/js/frameworkcorebundle.framework.form.search.js'
    'assets/js/frameworkcorebundle.app.js'
    output='js/app.js'
%}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

Fonts

We will look into all bundles in the src-folder for all the ttf and otf-files
in the Resources/assets/fonts-folder, these files will be copied to
assets/fonts-folder in the root directory. When this is done all the other
formats (eot, svg, ttf, woff) are created in the web/assets/fonts-folder.

You can link to the font-files with the compass-shortcurt font-url('filename')
in your scss-files.

Icons

We will look into all bundles in the src-folder for all the svg-files in the
Resources/assets/icons-folder, these files will be compiled into an iconfont
located in web/assets/fonts-folder in the root directory. A _icons.scss-file
will be stored in the assets/sass-folder.

Images

We will look into all bundles in the src-folder for all files in the
Resources/assets/images-folder, these files will be copied to the
web/assets/images-folder in the root directory. The folder structure you
(optionally) created will be preserved.

Important: make sure you don't have duplicate filenames as the files will be
overwritten.

You can link to the font-files with the compass-shortcurt image-url('filename')`
in your scss-files.

When running grunt build the images will be optimized for web with the
grunt-contrib-imagemin-plugin.

You can use the asset-method in twig templates like below:

<img src="{{ asset('assets/images/arrow_show_menu.png') }}" />

JS

We will look into all bundles in the src-folder for all files in the
Resources/assets/js-folder, these files will be copied to the
web/assets/js-folder in the root directory. The folder structure you
(optionally) created will be preserved.

You can use the asset-method in twig templates like below:

<img src="{{ asset('assets/js/sumo_plugins.js') }}" />

SASS/SCSS

We will look into all bundles in the src-folder for all files in the
Resources/assets/sass-folder, these files will be copied to the
assets/sass-folder in the root directory. The folder structure you
(optionally) created will be preserved.

After that the files will be compiled into web/assets/css. When running
grunt build the files will be compiled as minified as possible, so without
any comments.

When the sass/scss-files are compiled we use the
grunt-autoprefixer-plugin

If you want you can combine multiple generated css files into one by using
Assetic:

{% stylesheets
    'assets/css/1.css'
    'assets/css/2.css'
    filter='cssrewrite'
    output='css/combined.css'
%}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

But in most cases you will just use

{% stylesheets
    'assets/css/style.css'
    filter='cssrewrite'
    output='css/style.css'
%}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

Usage

While developing

grunt

We have implemented live-reload, so your changes will be reloaded in the
browser. This will only happen in the dev-environment.

Before launching your website

grunt build

You don't have to bother if you are using deployment as we will handle it for
you.

We will install bower through npm
In package.json all required (node-)modules will be listed.
As we will dump assetic, and use bower + grunt instead.
The files will be copied into place by grunt
We will loop all bundles in the src folder and move all the assets into one folder.
When that is done we will compile the sass-files
From now on you will be able to just run "grunt" and everything will be watched,
and the correct actions will be executed on file-change
@tijsverkoyen
Copy link
Member Author

Note that this is a work in progress

composer.json Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

These should be removed

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in cfc72be

As the fonts can be referenced in the css-files with a directory we should
preserver the folder structure
This is fixed by copying the file into the correct location.
When woff2-support isn't experimental anymore we should enable it in fontgen
This is fixed by copying the file into the correct location.
Copy link
Contributor

Choose a reason for hiding this comment

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

Je gebruikt zowel "prod" als "Production" in deze file, ik zou voor een consistente benaming gaan (en imo is production beter).

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in a7e727e426f7acb22598f28197aa1ae7a5f51518

@WouterSioen
Copy link
Contributor

When merging this, I'd squash some of the commits. I don't think it adds a lot of value to have 65 commits for this integration.

@tijsverkoyen
Copy link
Member Author

Squashed version of some commits in #5

@WouterSioen WouterSioen deleted the grunt-and-bower-instead-of-assetic branch February 17, 2015 17:03
@bjorvack bjorvack mentioned this pull request Jun 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants