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

Bye bye gulp #12043

Closed
wants to merge 5 commits into from
Closed

Bye bye gulp #12043

wants to merge 5 commits into from

Conversation

kulczy
Copy link
Member

@kulczy kulczy commented Nov 13, 2020

Q A
Branch? master
Bug fix? no
New feature? no
Related tickets follow-up of #10803 and #10827 and #13900
License MIT

I think it's time to say goodbye to the Gulp. This is the next part of the transition started #10803
Assets can be compiled using the following commands: yarn dev yarn build and yarn watch
I also encourage you to read the Webpack Encore documentation

@kulczy kulczy requested a review from a team as a code owner November 13, 2020 12:40
@Zales0123 Zales0123 added DX Issues and PRs aimed at improving Developer eXperience. Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.). labels Nov 13, 2020
@jacquesbh
Copy link
Member

jacquesbh commented Nov 16, 2020

Hi @kulczy!

Didn't you forget the logo in the checkout?
And in the emails as well?

@kulczy
Copy link
Member Author

kulczy commented Nov 17, 2020

@jacquesbh good point, thanks!

Copy link
Member

@jacquesbh jacquesbh left a comment

Choose a reason for hiding this comment

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

Nice nice nice!

@@ -1,5 +1,5 @@
<a class="item" href="{{ path('sylius_admin_dashboard') }}" style="padding: 13px 0;">
<div style="max-width: 90px; margin: 0 auto;">
<img src="{{ asset('assets/admin/img/admin-logo.svg') }}" class="ui fluid image">
<img src="{{ asset('build/admin/images/admin-logo.svg', 'admin') }}" class="ui fluid image">
Copy link
Member

Choose a reason for hiding this comment

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

These changes seem like an obvious candidate for UPGRADE file

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 reduce those changes to be as minimal as possible? Leaving the asset path the same as before?

Copy link
Member

Choose a reason for hiding this comment

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

Actually this is not possible. This is how Encore works.
And keeping the same path will lead to some conflicts with other bundles.

Copy link
Contributor

@misaon misaon Nov 18, 2020

Choose a reason for hiding this comment

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

@lchrusciel @pamil Its possible..

  .configureFilenames({
    images: Encore.isProduction() ? 'img/[name].[hash:8].[ext]' : 'img/[name].[ext]',
  })

See the complete code implementation below in the thread.

@@ -1 +1 @@
{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'assets/admin/js/app.js'} %}
{{ encore_entry_script_tags('admin-entry', null, 'admin') }}
Copy link
Member

Choose a reason for hiding this comment

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

This should be documented as well

config/packages/assets.yaml Outdated Show resolved Hide resolved
config/packages/webpack_encore.yaml Outdated Show resolved Hide resolved
@misaon
Copy link
Contributor

misaon commented Nov 18, 2020

We have been using Webpack for our Sylius compilation for a long time, without changes in Sylius Twig admin templates. Even in production and without a problem. I am sending our configuration for inspiration.

const Encore = require('@symfony/webpack-encore')

if (!Encore.isRuntimeEnvironmentConfigured()) {
  Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev')
}

// Shop config
Encore.setOutputPath('public/assets/shop/')
  .setPublicPath('/assets/shop')
  .splitEntryChunks(Encore.isProduction())
  .enableSingleRuntimeChunk()
  .cleanupOutputBeforeBuild()
  .enableBuildNotifications()
  .enableSourceMaps(!Encore.isProduction())
  .enableVersioning(Encore.isProduction())
  .enableIntegrityHashes(Encore.isProduction())
  .enableSassLoader()
  .enableVueLoader(() => {}, { runtimeCompilerBuild: false })
  .autoProvidejQuery()
  .configureBabel(
    (babelConfig) => {
      babelConfig.plugins.push('@babel/plugin-proposal-class-properties')
    },
    {
      includeNodeModules: ['@oxyshop'],
    }
  )
  .configureBabelPresetEnv((config) => {
    config.useBuiltIns = 'usage'
    config.corejs = 3
  })

  // Fix issue: https://github.com/symfony/webpack-encore/issues/808
  .configureUrlLoader({
    images: {
      limit: 0,
      esModule: false,
    },
  })

  .addEntry('shop-entry', './assets/shop/entry.js')

const shopConfig = Encore.getWebpackConfig()
shopConfig.name = 'shop'

Encore.reset()

// Admin config
Encore.setOutputPath('public/assets/admin/')
  .setPublicPath('/assets/admin')
  .splitEntryChunks(Encore.isProduction())
  .enableSingleRuntimeChunk()
  .cleanupOutputBeforeBuild()
  .enableBuildNotifications()
  .enableSourceMaps(!Encore.isProduction())
  .enableVersioning(Encore.isProduction())
  .enableIntegrityHashes(Encore.isProduction())
  .enableSassLoader()
  .autoProvidejQuery()
  .configureBabelPresetEnv((config) => {
    config.useBuiltIns = 'usage'
    config.corejs = 3
  })
  .configureFilenames({
    images: Encore.isProduction() ? 'img/[name].[hash:8].[ext]' : 'img/[name].[ext]',
  })

  // Fix CKEditor 4 integration into Webpack
  .copyFiles([
    {
      from: './node_modules/ckeditor/',
      to: 'ckeditor/[path][name].[ext]',
      pattern: /\.(js|css)$/,
      includeSubdirectories: false,
    },
    { from: './node_modules/ckeditor/adapters', to: 'ckeditor/adapters/[path][name].[ext]' },
    { from: './node_modules/ckeditor/lang', to: 'ckeditor/lang/[path][name].[ext]' },
    { from: './node_modules/ckeditor/plugins', to: 'ckeditor/plugins/[path][name].[ext]' },
    { from: './node_modules/ckeditor/skins', to: 'ckeditor/skins/[path][name].[ext]' },
  ])

  // Fix issue: https://github.com/symfony/webpack-encore/issues/808
  .configureUrlLoader({
    images: {
      limit: 0,
      esModule: false,
    },
  })
  .addEntry('admin-entry', './assets/admin/entry.js')

const adminConfig = Encore.getWebpackConfig()
adminConfig.externals = {
  ...adminConfig.externals,
  window: 'window',
  document: 'document',
}
adminConfig.name = 'admin'

module.exports = {
  shop: shopConfig,
  admin: adminConfig,
}

Only scripts and stylesheets twig files was changed:

Links:

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

Scripts:

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

webpack_encore.yaml:

webpack_encore:
    builds:
        shop: '%kernel.project_dir%/public/assets/shop'
        admin: '%kernel.project_dir%/public/assets/admin'
    output_path: false

assets.yaml:

framework:
    assets:
        json_manifest_path: '%kernel.project_dir%/public/assets/admin/manifest.json'
        packages:
            shop:
                json_manifest_path: '%kernel.project_dir%/public/assets/shop/manifest.json'

We use own implementation of Shop templates based on Bootstrap. But you can customize configureFilenames method for it.

Cheers! 🚀

@kulczy
Copy link
Member Author

kulczy commented Nov 19, 2020

Hi, @misaon thanks for that. It looks good, but I think it's a bit hacky because, in assets.yaml, shop config uses custom output, but the admin uses the default one. So indeed, in that case, we can avoid changing asset functions, but only in admin bundle. What I want to achieve is a clear separation between these two, to avoid confusion, and that requires changes in admin files to add a second parameter in the assets function.

@kulczy
Copy link
Member Author

kulczy commented Nov 19, 2020

And @pamil @lchrusciel when it comes to paths, I can leave current ones, but it can cause some problems during migration. The first that comes to mind is that webpack clear folders before every build, so if these folders contain any files that have been added manually or does not compile via webpack, they will be gone. I think that new folders will be a better idea, WDYT?

@misaon
Copy link
Contributor

misaon commented Nov 19, 2020

Hi, @misaon thanks for that. It looks good, but I think it's a bit hacky because, in assets.yaml, shop config uses custom output, but the admin uses the default one. So indeed, in that case, we can avoid changing asset functions, but only in admin bundle. What I want to achieve is a clear separation between these two, to avoid confusion, and that requires changes in admin files to add a second parameter in the assets function.

@kulczy you're right this solution is a bit hacky. however, if people use sylius and do not want to change assets in all of their templates on shop front, this proposal is the easiest way to achieve this without work. You can reverse this logic and set shop as the default package, not administration. then the changes in administration would take effect after updating the sylius composer package.

@minimit
Copy link

minimit commented Feb 1, 2021

We might want to update to 1.0.0 https://github.com/symfony/webpack-encore/releases

Watch out with the new version of webpack encore 1.0.0 the manifest.json is all wrong.

{
  "build/shop/shop-entry.css": "/build/shop/shop-entry.css",
  "build/shop/shop-entry.js": "/build/shop/shop-entry.js",
  "build/shop/shop-entry.eot": "/build/shop/fonts/outline-icons.752905fa.eot",
  "build/shop/shop-entry.svg": "/build/shop/images/outline-icons.9c4845b4.svg",
  "build/shop/shop-entry.ttf": "/build/shop/fonts/outline-icons.53671035.ttf",
  "build/shop/shop-entry.woff": "/build/shop/fonts/outline-icons.ddae9b1b.woff",
  "build/shop/shop-entry.woff2": "/build/shop/fonts/outline-icons.687a4990.woff2",
  "build/shop/shop-entry.png": "/build/shop/images/logo.72a9465e.png",
  "build/shop/shop-entry.gif": "/build/shop/images/loading.f657825a.gif",
  "build/shop/shop-entry.jpg": "/build/shop/images/homepage-banner.8d8f072a.jpg",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/brand-icons.svg": "/build/shop/images/brand-icons.6729d297.svg",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/icons.svg": "/build/shop/images/icons.62d9dae4.svg",
  "build/shop/vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/private/img/homepage-banner.jpg": "/build/shop/images/homepage-banner.8d8f072a.jpg",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/outline-icons.svg": "/build/shop/images/outline-icons.9c4845b4.svg",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/icons.eot": "/build/shop/fonts/icons.a01e3f2d.eot",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/icons.ttf": "/build/shop/fonts/icons.c656b8ca.ttf",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/brand-icons.eot": "/build/shop/fonts/brand-icons.d68fa3e6.eot",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/brand-icons.ttf": "/build/shop/fonts/brand-icons.65a2fb6d.ttf",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/brand-icons.woff": "/build/shop/fonts/brand-icons.cac87dc0.woff",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/brand-icons.woff2": "/build/shop/fonts/brand-icons.278156e4.woff2",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/icons.woff": "/build/shop/fonts/icons.425399f8.woff",
  "build/shop/vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/private/img/sylius-plus-banner.png": "/build/shop/images/sylius-plus-banner.fff4fe72.png",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/icons.woff2": "/build/shop/fonts/icons.38c6d8ba.woff2",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/outline-icons.eot": "/build/shop/fonts/outline-icons.752905fa.eot",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/outline-icons.ttf": "/build/shop/fonts/outline-icons.53671035.ttf",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/images/flags.png": "/build/shop/images/flags.99f63ae7.png",
  "build/shop/vendor/sylius/sylius/src/Sylius/Bundle/UiBundle/Resources/private/img/logo.png": "/build/shop/images/logo.72a9465e.png",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/outline-icons.woff": "/build/shop/fonts/outline-icons.ddae9b1b.woff",
  "build/shop/node_modules/semantic-ui-css/themes/default/assets/fonts/outline-icons.woff2": "/build/shop/fonts/outline-icons.687a4990.woff2",
  "build/shop/node_modules/lightbox2/dist/images/loading.gif": "/build/shop/images/loading.f657825a.gif",
  "build/shop/vendor/sylius/sylius/src/Sylius/Bundle/UiBundle/Resources/private/img/avatar.png": "/build/shop/images/avatar.fa261429.png",
  "build/shop/node_modules/lightbox2/dist/images/prev.png": "/build/shop/images/prev.0edc57cc.png",
  "build/shop/node_modules/lightbox2/dist/images/next.png": "/build/shop/images/next.62074ac7.png",
  "build/shop/node_modules/lightbox2/dist/images/close.png": "/build/shop/images/close.0cfd6489.png"
}

symfony/webpack-encore#907

@minimit
Copy link

minimit commented Feb 12, 2021

Now it's ok to use webpack encore 1.0.6 https://github.com/symfony/webpack-encore/releases/tag/v1.0.6

@vvasiloi
Copy link
Contributor

Why is this not moving forward?
I've been using Webpack with Sylius for 2 years already, maybe I can help...

@probot-autolabeler probot-autolabeler bot added Admin AdminBundle related issues and PRs. Maintenance CI configurations, READMEs, releases, etc. Shop ShopBundle related issues and PRs. labels Mar 18, 2021
@kulczy kulczy force-pushed the go-webpack branch 3 times, most recently from 9b78ab7 to e5281ca Compare March 18, 2021 11:24
@kulczy
Copy link
Member Author

kulczy commented Mar 19, 2021

@vvasiloi now we have to play with it, then implement it to the Standard. If after 2 yrs of working with it, you have any ideas about what could go wrong, let me know

@vvasiloi
Copy link
Contributor

@kulczy I will look into it in weekend. Besides the Sylius-Standard, maybe also update the plugin skeleton and add support for themes out-of-the-box?

@kayue
Copy link
Contributor

kayue commented Mar 19, 2021

I have webpack and encore in my project working for months as well. It makes loading script in Sylius much easier.

This is what my assets/admin/entry.js looks like. (For admin panel)

import 'sylius/bundle/AdminBundle/Resources/private/entry';
import { startStimulusApp } from '@symfony/stimulus-bridge';

// Registers Stimulus controllers from controllers.json and in the controllers/ directory
export const app = startStimulusApp(require.context(
    '@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
    true,
    /\.(j|t)sx?$/
));

@stloyd
Copy link
Contributor

stloyd commented Apr 3, 2021

@pamil @lchrusciel I would love to see this in 1.10 ;)

@CoderMaggie CoderMaggie added the Help Wanted Issues needing help and clarification. label May 10, 2022
package.json Outdated
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"dedent": "^0.7.0",
"@symfony/webpack-encore": "^1.1.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Upgrading to v2 would be nice 😃

@kulczy
Copy link
Member Author

kulczy commented May 18, 2022

Hello again xD After rebase, it looks like everything works, even with the new theme, but there are a few things to mention.

I had to replace Semantic with Fomantic, due to a typo in Semantic css file 🤦‍♂️ - Webpack 5 will not compile it anymore. Of course, it's not so easy xD - Fomantic fixed it but this has not yet arrived in a stable release, so for now, I had to use beta version. Because the whole styles are changed, minor CSS bugs may occur.

The second thing - upgrade instructions. As probably everybody managed the assets in their own way, I have no idea what to write in the Upgrade file to make it easier for people to update from gulp to webpack, so I need your help. If anyone has an idea, feel free to commit

@jakubtobiasz
Copy link
Contributor

@kulczy I see some tests are failing due to

Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template ("Could not find the entrypoints file from Webpack: the file "/home/runner/work/Sylius/Sylius/public/build/shop/entrypoints.json" does not exist.").

Idk if it was failing previously 😿 , I'll check it later and open next PR against your fork as previously.

@Nek-
Copy link
Contributor

Nek- commented Jun 14, 2022

I had to replace Semantic with Fomantic, due to a typo in Semantic css file 🤦‍♂️

I think this is a nogo. See #10463 (comment)

But as an alternative I suggest you to add a package that fixes it:

// packages.json
{
  // ...
  "devDependencies": {
    // ...
    "@semantic-ui-react/css-patch": "^1.0.0",
 },
  "scripts": {
    "postinstall": "semantic-ui-css-patch"
    // ...
  }
// ...
}

This is suboptimal but responds to the nogo of the sylius team, we use it in production and it works just fine. (I prefer your solution)

@aleho
Copy link
Contributor

aleho commented Jun 14, 2022

FYI, using the GitHub sources of Semantic-UI directly, the commit fixing the typo can be imported without any further patching needed:

This package.json

{
  "dependencies": {
    "@symfony/webpack-encore": "^2.1.0",
    "semantic-ui-css": "github:Semantic-Org/Semantic-UI-CSS"
  }
}

compiles without issues for us.

(See Semantic-Org/Semantic-UI-CSS/issues/81, the project seems to be pretty dead.)

@kulczy
Copy link
Member Author

kulczy commented Jun 22, 2022

I have another idea, let's put this file into our repo. This is only one unmaintained CSS. By doing that, we could fix any errors regularly, and if a better option appears, we will go back to npm. WDYT?

@jakubtobiasz
Copy link
Contributor

Hi 🙋🏼‍♂️!

I am closing this PR as we have been continuing it in #14330. Thank you @kulczy for your work!

@kulczy kulczy deleted the go-webpack branch March 19, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin AdminBundle related issues and PRs. DX Issues and PRs aimed at improving Developer eXperience. Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.). Help Wanted Issues needing help and clarification. Maintenance CI configurations, READMEs, releases, etc. Shop ShopBundle related issues and PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.