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

Add Webpack Encore #10803

Merged
merged 1 commit into from
Nov 6, 2019
Merged

Add Webpack Encore #10803

merged 1 commit into from
Nov 6, 2019

Conversation

kulczy
Copy link
Member

@kulczy kulczy commented Oct 29, 2019

This is the first step to completely remove the gulp. For now, lets you choose whether you want to use the gulp or webpack. By default, it uses the gulp as before.

To switch to the webpack, just change the assets paths:

// src/Sylius/Bundle/AdminBundle/Resources/views/_scripts.html.twig

{{ encore_entry_script_tags('admin-entry', null, 'admin') }}
// src/Sylius/Bundle/AdminBundle/Resources/views/_styles.html.twig

{{ encore_entry_link_tags('admin-entry', null, 'admin') }}
// src/Sylius/Bundle/AdminBundle/Resources/views/_logo.html.twig

{{ asset('build/admin/images/admin-logo.svg', 'admin') }}

And for shop:

// src/Sylius/Bundle/ShopBundle/Resources/views/_scripts.html.twig

{{ encore_entry_script_tags('shop-entry', null, 'shop') }}
// src/Sylius/Bundle/ShopBundle/Resources/views/_styles.html.twig

{{ encore_entry_link_tags('shop-entry', null, 'shop') }}
// src/Sylius/Bundle/ShopBundle/Resources/views/_header.html.twig

{{ asset('build/shop/images/logo.png', 'shop') }}

The paths should be changed for each asset you use.

To build the assets, run:

yarn encore dev or yarn encore production or yarn encore dev-server

When compiling assets, errors may appear (they don't break the build), due to different babel configuration for gulp and webpack. Once you decide to use the webpack you can delete the gulpfile.babel.js and .babelrc from the root directory - then the errors will stop appearing.


➡️➡️➡️ Webpack Encore docs

@kulczy kulczy requested a review from a team as a code owner October 29, 2019 12:24
@CoderMaggie CoderMaggie added DX Issues and PRs aimed at improving Developer eXperience. RFC Discussions about potential changes or new features. UX Issues and PRs aimed at improving User eXperience. labels Oct 29, 2019
@gabiudrescu
Copy link
Contributor

gabiudrescu commented Oct 29, 2019

  1. Reproducible builds with Webpack are nightmare; further reads here:

Once you decide to use the webpack you can delete the gulpfile.babel.js and .babelrc from the root directory - then the errors will stop appearing.

Could be automated with symfony-flex, I think. but I don't know if it should

  1. can we challenge now the usage of yarn instead of npm? why not use npm instead of yarn?

@kulczy
Copy link
Member Author

kulczy commented Oct 29, 2019

This is just the first step to implement the Webpack into Sylius, Sylius-standard and plugins. When everything works and the gulp is no longer needed then we will think about improvements

.gitignore Outdated
@@ -40,3 +41,8 @@
###> phpunit/phpunit ###
/phpunit.xml
###< phpunit/phpunit ###

###> symfony/webpack-encore-bundle ###
npm-debug.log
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
npm-debug.log
/npm-debug.log

.gitignore Outdated

###> symfony/webpack-encore-bundle ###
npm-debug.log
yarn-error.log
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
yarn-error.log
/yarn-error.log

import 'semantic-ui-css/semantic.css';
import 'lightbox2/dist/css/lightbox.min.css';

import '../../../UiBundle/Resources/private/js/app';
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we pass uiBundlePath variable from webpack.config.js here? Going outside of the current bundle seems a bit like crossing some boundary.

I don't hold this opinion strongly, but I want to discuss it first :)

Copy link
Member Author

Choose a reason for hiding this comment

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

in the webpack.config.js file we have the alias sylius/ui which is necessary for the app.js files. We can create another alias, e.g. sylius/ui_resources and then we'll be able to use it instead of ../../../UiBundle/Resources/private

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good! This way we'll get the absolute path to the resources. What is the naming convention here, should it be sylius/ui_resources or sylius/ui-resources?

Copy link
Member Author

Choose a reason for hiding this comment

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

imo sylius/ui-resources

@pamil pamil merged commit 4f61fe7 into Sylius:master Nov 6, 2019
@pamil
Copy link
Contributor

pamil commented Nov 6, 2019

Thank you, Szymon! 🎉

@kulczy kulczy mentioned this pull request Nov 7, 2019
Zales0123 added a commit that referenced this pull request Nov 8, 2019
This PR was merged into the 1.7-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | yes
| Related tickets | fixes #10803 

This PR removes webpack-encore-bundle from dependencies to avoid errors in plugins that have no webpack configuration

### To start using the webpack you need to:

1. Install webpack-encore-bundle
```
composer require symfony/webpack-encore-bundle
```

2. Edit `config/packages/assets.yaml` file
```yml
framework:
    assets:
        packages:
            shop:
                json_manifest_path: '%kernel.project_dir%/public/build/shop/manifest.json'
            admin:
                json_manifest_path: '%kernel.project_dir%/public/build/admin/manifest.json'
```

3. Edit `config/packages/webpack_encore.yaml` file
```yml
webpack_encore:
    output_path: '%kernel.project_dir%/public/build/default'
    builds:
        shop: '%kernel.project_dir%/public/build/shop'
        admin: '%kernel.project_dir%/public/build/admin'
```

4. Change the assets paths for admin and shop:
```js
// src/Sylius/Bundle/AdminBundle/Resources/views/_scripts.html.twig

{{ encore_entry_script_tags('admin-entry', null, 'admin') }}
```

```js
// src/Sylius/Bundle/AdminBundle/Resources/views/_styles.html.twig

{{ encore_entry_link_tags('admin-entry', null, 'admin') }}
```

```js
// src/Sylius/Bundle/AdminBundle/Resources/views/_logo.html.twig

{{ asset('build/admin/images/admin-logo.svg', 'admin') }}
```

```js
// src/Sylius/Bundle/ShopBundle/Resources/views/_scripts.html.twig

{{ encore_entry_script_tags('shop-entry', null, 'shop') }}
```

```js
// src/Sylius/Bundle/ShopBundle/Resources/views/_styles.html.twig

{{ encore_entry_link_tags('shop-entry', null, 'shop') }}
```

```js
// src/Sylius/Bundle/ShopBundle/Resources/views/_header.html.twig

{{ asset('build/shop/images/logo.png', 'shop') }}
```

The paths should be changed for each asset you use.

5. To build the assets, run:
```bash
yarn encore dev
# or
yarn encore production
# or
yarn encore dev-server
```

When compiling assets, errors may appear (they don't break the build), due to different babel configuration for gulp and webpack. Once you decide to use the webpack you can delete the `gulpfile.babel.js` and `.babelrc` from the root directory - then the errors will stop appearing.

---

➡️➡️➡️  [Webpack Encore docs](https://symfony.com/doc/current/frontend.html#webpack-encore)

Commits
-------

0acde3a New Webpack approach
@kulczy kulczy mentioned this pull request Nov 13, 2020
@kulczy kulczy deleted the webpack branch April 4, 2022 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Issues and PRs aimed at improving Developer eXperience. RFC Discussions about potential changes or new features. UX Issues and PRs aimed at improving User eXperience.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants