Skip to content

Encore tweaks! #8035

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
10 changes: 6 additions & 4 deletions frontend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ Other Front-End Articles
........................

.. toctree::
:maxdepth: 1
:hidden:
:glob:

frontend/*
frontend/encore/installation
frontend/encore/simple-example
frontend/encore/*

.. toctree::
:hidden:
:maxdepth: 1
:glob:

frontend/encore/*
frontend/*

.. _`Webpack Encore`: https://www.npmjs.com/package/@symfony/webpack-encore
.. _`Webpack`: https://webpack.js.org/
Expand Down
5 changes: 3 additions & 2 deletions frontend/encore/bootstrap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ a ``global.scss`` file, import it from there:
// assets/css/global.scss

// customize some Bootstrap variables
$brand-primary: darken(#428bca, 20%);
$brand-primary: darken(#428bca, 20%);

// the ~ allows you to reference things in node_modules
@import '~bootstrap-sass/assets/stylesheets/bootstrap';
Expand All @@ -41,7 +41,7 @@ this, you can use the ``resolve_url_loader`` option:

// webpack.config.js
Encore
+ enableSassLoader({
+ .enableSassLoader({
+ 'resolve_url_loader' => false
+ })
;
Expand Down Expand Up @@ -79,6 +79,7 @@ Next, make sure to call ``.autoProvidejQuery()`` in your ``webpack.config.js`` f
Encore
// ...
+ .autoProvidejQuery()
;

This is needed because Bootstrap expects jQuery to be available as a global
variable. Now, require bootstrap from any of your JavaScript files:
Expand Down
8 changes: 4 additions & 4 deletions frontend/encore/installation.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Installation
============

First, make sure you `install Node.js`_ and also the `yarn package manager`_.
First, make sure you `install Node.js`_ and also the `Yarn package manager`_.

Then, install Encore into your project with yarn:
Then, install Encore into your project with Yarn:

.. code-block:: terminal

Expand All @@ -21,11 +21,11 @@ is also created/updated. When using npm 5, a ``package-lock.json`` file is creat
.. tip::

You should commit ``package.json`` and ``yarn.lock`` (or ``package-lock.json``
if using npm) to version control, but ignore ``node_modules/``.
if using npm 5) to version control, but ignore ``node_modules/``.

Next, create your ``webpack.config.js`` in :doc:`/frontend/encore/simple-example`!

.. _`install Node.js`: https://nodejs.org/en/download/
.. _`yarn package manager`: https://yarnpkg.com/lang/en/docs/install/
.. _`Yarn package manager`: https://yarnpkg.com/lang/en/docs/install/
.. _`npm`: https://www.npmjs.com/
.. _`yarn`: https://yarnpkg.com/
24 changes: 12 additions & 12 deletions frontend/encore/simple-example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,16 @@ may want also to :doc:`create a shared entry </frontend/encore/shared-entry>` fo
Requiring CSS Files from JavaScript
-----------------------------------

You can also require CSS files from your JavaScript:
Above, you created an entry called ``app`` that pointed to ``main.js``:

.. code-block:: javascript

Encore
// ...
.addEntry('app', './assets/js/main.js')
Copy link
Member

Choose a reason for hiding this comment

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

missing semicolon

Copy link
Contributor

@sstok sstok Jun 13, 2017

Choose a reason for hiding this comment

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

it's on the next line, and JavaScript will work just fine here 😛

But don't leave a trailing comma for better diff readability!, oh God no, we can't have that!! the Angels will the weep the blood of innocent, the sky will fall down like ashes, the seas will boil, the land will be engulfed with hordes of flies, chaos will rule the land for a 1000 years, nothing will ever grow anymore, all is dead. And.... ahhh, the compiler will fail to work 😑 JavaScript - forgives a missing semi-colon (when there is a space), but chokes on a trailing comma (because accepting that would be blasphemy).

Copy link
Member

Choose a reason for hiding this comment

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

I am pretty sure it wasn't there when I commented. :)

;

Once inside ``main.js``, you can even require CSS files:

.. code-block:: javascript

Expand All @@ -149,17 +158,8 @@ You can also require CSS files from your JavaScript:
// a CSS file with the same name as the entry js will be output
require('../css/main.scss');

In this case, ``main.js`` is being added to an entry called ``app`` in ``webpack.config.js``:

.. code-block:: javascript

Encore
// ...
.addEntry('app', './assets/js/main.js')

As soon as you require a CSS file, both an ``app.js`` **and** an ``app.css`` file
will be created. You'll need to add a link tag to the ``app.css`` file in your
templates:
Now, both an ``app.js`` **and** an ``app.css`` file will be created. You'll need
to add a link tag to the ``app.css`` file in your templates:

.. code-block:: diff

Expand Down