-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[WCM] Updating the Encore documentation + New recipe #10128
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
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
Encore Installation (without Symfony Flex) | ||
========================================== | ||
|
||
.. tip: | ||
|
||
If your project uses Symfony Flex, read :doc:`/frontend/encore/installation` | ||
for easier instructions. | ||
|
||
Installing Encore | ||
----------------- | ||
|
||
Install Encore into your project via Yarn: | ||
|
||
.. code-block:: terminal | ||
|
||
$ yarn add @symfony/webpack-encore --dev | ||
|
||
.. note:: | ||
|
||
If you prefer to use `npm`_, no problem! Run ``npm install @symfony/webpack-encore --save-dev``. | ||
|
||
This command creates (or modifies) a ``package.json`` file and downloads dependencies | ||
into a ``node_modules/`` directory. Yarn also creates/updates a ``yarn.lock`` | ||
(called ``package-lock.json`` if you use npm version 5+). | ||
|
||
.. tip:: | ||
|
||
You *should* commit ``package.json`` and ``yarn.lock`` (or ``package-lock.json`` | ||
if using npm 5) to version control, but ignore ``node_modules/``. | ||
|
||
Creating the webpack.config.js File | ||
----------------------------------- | ||
|
||
Next, create a new ``webpack.config.js`` file at the root of your project: | ||
|
||
.. code-block:: js | ||
|
||
var Encore = require('@symfony/webpack-encore'); | ||
|
||
Encore | ||
// directory where compiled assets will be stored | ||
.setOutputPath('public/build/') | ||
// public path used by the web server to access the output path | ||
.setPublicPath('/build') | ||
// only needed for CDN's or sub-directory deploy | ||
//.setManifestKeyPrefix('build/') | ||
|
||
/* | ||
* ENTRY CONFIG | ||
* | ||
* Add 1 entry for each "page" of your app | ||
* (including one that's included on every page - e.g. "app") | ||
* | ||
* Each entry will result in one JavaScript file (e.g. app.js) | ||
* and one CSS file (e.g. app.css) if you JavaScript imports CSS. | ||
*/ | ||
.addEntry('app', './assets/js/app.js') | ||
//.addEntry('page1', './assets/js/page1.js') | ||
//.addEntry('page2', './assets/js/page2.js') | ||
|
||
.cleanupOutputBeforeBuild() | ||
.enableSourceMaps(!Encore.isProduction()) | ||
// enables hashed filenames (e.g. app.abc123.css) | ||
.enableVersioning(Encore.isProduction()) | ||
|
||
// uncomment if you use TypeScript | ||
//.enableTypeScriptLoader() | ||
|
||
// uncomment if you use Sass/SCSS files | ||
//.enableSassLoader() | ||
|
||
// uncomment if you're having problems with a jQuery plugin | ||
//.autoProvidejQuery() | ||
; | ||
|
||
module.exports = Encore.getWebpackConfig(); | ||
|
||
Next, create a new ``assets/js/app.js`` file with some basic JavaScript *and* | ||
import some JavaScript: | ||
|
||
.. code-block:: javascript | ||
|
||
// assets/js/app.js | ||
|
||
require('../css/app.css'); | ||
|
||
console.log('Hello Webpack Encore'); | ||
|
||
And the new ``assets/css/app.css`` file: | ||
|
||
.. code-block:: css | ||
|
||
// assets/css/app.css | ||
body { | ||
background-color: lightgray; | ||
} | ||
|
||
You'll customize and learn more about these file in :doc:`/frontend/encore/simple-example`. | ||
|
||
.. _`npm`: https://www.npmjs.com/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,28 @@ | ||
Encore Installation | ||
Installating Encore | ||
=================== | ||
|
||
First, make sure you `install Node.js`_ and also the `Yarn package manager`_. | ||
|
||
Then, install Encore into your project with Yarn: | ||
Option A) If you are using Symfony Flex | ||
--------------------------------------- | ||
|
||
.. code-block:: terminal | ||
|
||
$ yarn add @symfony/webpack-encore --dev | ||
|
||
.. note:: | ||
|
||
If you want to use `npm`_ instead of `yarn`_: | ||
|
||
.. code-block:: terminal | ||
If you are using Symfony flex, you can easily setup your app by running: | ||
|
||
$ npm install @symfony/webpack-encore --save-dev | ||
|
||
.. tip:: | ||
|
||
If you are using Flex for your project, you can initialize your project for Encore via: | ||
|
||
.. code-block:: terminal | ||
|
||
$ composer require symfony/webpack-encore-pack | ||
$ yarn install | ||
.. code-block:: terminal | ||
|
||
This will create a ``webpack.config.js`` file, add the ``assets/`` directory, and add ``node_modules/`` to | ||
``.gitignore``. | ||
$ composer require webpack-encore | ||
$ yarn install | ||
|
||
This command creates (or modifies) a ``package.json`` file and downloads dependencies | ||
into a ``node_modules/`` directory. When using Yarn, a file called ``yarn.lock`` | ||
is also created/updated. When using npm 5, a ``package-lock.json`` file is created/updated. | ||
This will create a ``webpack.config.js`` file, add the ``assets/`` directory, and | ||
add ``node_modules/`` to ``.gitignore``. | ||
|
||
.. tip:: | ||
Nice work! Write your first JavaScript and CSS by reading :doc:`/frontend/encore/simple-example`! | ||
|
||
You should commit ``package.json`` and ``yarn.lock`` (or ``package-lock.json`` | ||
if using npm 5) to version control, but ignore ``node_modules/``. | ||
Option B) Without Symfony Flex | ||
------------------------------ | ||
|
||
Next, create your ``webpack.config.js`` in :doc:`/frontend/encore/simple-example`! | ||
If your project doesn't use Symfony Flex, you can still install Encore easily via | ||
yarn or npm. See :doc:`/frontend/encore/installation-no-flex`. | ||
|
||
.. _`install Node.js`: https://nodejs.org/en/download/ | ||
.. _`Yarn package manager`: https://yarnpkg.com/lang/en/docs/install/ | ||
.. _`npm`: https://www.npmjs.com/ | ||
.. _`yarn`: https://yarnpkg.com/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not do like you did with the non-flex installation page (with a tip at the top)? It's kind of ugly to have options on the "main" page about Encore installation as 99% of the time, people will have Flex.