From 4b2e742878927e1a596972324c386291fbba0693 Mon Sep 17 00:00:00 2001 From: vcarroy Date: Wed, 23 Oct 2024 12:11:46 +0200 Subject: [PATCH] chore : Simplification de la conf webpack --- config/packages/webpack_encore.yaml | 45 +---------------------- templates/base.html.twig | 8 ++--- webpack.config.js | 56 +++-------------------------- 3 files changed, 10 insertions(+), 99 deletions(-) diff --git a/config/packages/webpack_encore.yaml b/config/packages/webpack_encore.yaml index d0569a4..17b53f8 100644 --- a/config/packages/webpack_encore.yaml +++ b/config/packages/webpack_encore.yaml @@ -2,53 +2,10 @@ webpack_encore: # The path where Encore is building the assets - i.e. Encore.setOutputPath() # If multiple builds are defined (as shown below), you can disable the default build: # output_path: false - output_path: false - builds: - appConfig: '%kernel.project_dir%/public/build/app' - themeConfig: '%kernel.project_dir%/public/build/theme' + output_path: "%kernel.project_dir%/public/build" # Set attributes that will be rendered on all script and link tags script_attributes: defer: true # Uncomment (also under link_attributes) if using Turbo Drive # https://turbo.hotwired.dev/handbook/drive#reloading-when-assets-change # 'data-turbo-track': reload - # link_attributes: - # Uncomment if using Turbo Drive - # 'data-turbo-track': reload - - # If using Encore.enableIntegrityHashes() and need the crossorigin attribute (default: false, or use 'anonymous' or 'use-credentials') - # crossorigin: 'anonymous' - - # Preload all rendered script and link tags automatically via the HTTP/2 Link header - # preload: true - - # Throw an exception if the entrypoints.json file is missing or an entry is missing from the data - # strict_mode: false - - # If you have multiple builds: - # builds: - # frontend: '%kernel.project_dir%/public/frontend/build' - - # pass the build name as the 3rd argument to the Twig functions - # {{ encore_entry_script_tags('entry1', null, 'frontend') }} - - # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes) - # Put in config/packages/prod/webpack_encore.yaml - # cache: true - -framework: - assets: - packages: - app: - json_manifest_path: '%kernel.project_dir%/public/build/app/manifest.json' - theme: - json_manifest_path: '%kernel.project_dir%/public/build/theme/manifest.json' -#when@prod: -# webpack_encore: -# # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes) -# # Available in version 1.2 -# cache: true - -#when@test: -# webpack_encore: -# strict_mode: false diff --git a/templates/base.html.twig b/templates/base.html.twig index 10e5528..fc55b87 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -4,16 +4,16 @@ {% block title %}Welcome!{% endblock %} {% block stylesheets %} - {{ encore_entry_link_tags('app', null, 'appConfig') }} - {{ encore_entry_link_tags('bootstrap-css', null, 'appConfig') }} + {{ encore_entry_link_tags('app') }} + {{ encore_entry_link_tags('bootstrap-css') }} {% endblock %} {% block body %}{% endblock %} {% block javascripts %} - {{ encore_entry_script_tags('app', null, 'appConfig') }} - {{ encore_entry_script_tags('bootstrap-js', null, 'appConfig') }} + {{ encore_entry_script_tags('app') }} + {{ encore_entry_script_tags('bootstrap-js') }} {% endblock %} diff --git a/webpack.config.js b/webpack.config.js index daa962a..6ad6343 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -11,11 +11,11 @@ const basePath = process.env.BASE_PATH || '' // Definition de AppConfig Encore // directory where compiled assets will be stored - .setOutputPath('public/build/app/') + .setOutputPath('public/build/') // public path used by the web server to access the output path - .setPublicPath(basePath + '/build/app') + .setPublicPath(basePath + '/build/') // only needed for CDN's or sub-directory deploy - .setManifestKeyPrefix('build/app') + .setManifestKeyPrefix('build') /* * ENTRY CONFIG @@ -26,6 +26,7 @@ Encore .addEntry('app', './assets/app.js') .addEntry('bootstrap-css', './assets/styles/bootstrap.scss') .addEntry('bootstrap-js', './assets/app-bootstrap.js') + .addEntry('theme','./public/theme-entrypoint.js') // When enabled, Webpack "splits" your files into smaller pieces for greater optimization. .splitEntryChunks() @@ -59,53 +60,6 @@ Encore .enablePostCssLoader() .autoProvidejQuery() .enableSassLoader() - // build the first configuration - const appConfig = Encore.getWebpackConfig(); - - // Set a unique name for the config (needed later!) - appConfig.name = 'appConfig'; - - // reset Encore to build the second config - Encore.reset(); - -// Definition de themeConfig -Encore - // directory where compiled assets will be stored - .setOutputPath('public/build/theme/') - // public path used by the web server to access the output path - .setPublicPath(basePath + '/build/theme') - // only needed for CDN's or sub-directory deploy - .setManifestKeyPrefix('build/theme') - - .addEntry('theme','./assets/theme-entrypoint.js') - .addEntry('bootstrap-css', './assets/styles/bootstrap.scss') - .addEntry('bootstrap-js', './assets/app-bootstrap.js') - - .splitEntryChunks() - .enableSingleRuntimeChunk() - .cleanupOutputBeforeBuild() - .enableBuildNotifications() - .enableSourceMaps(false) - .enableVersioning(false) - .configureBabel((config) => { - config.plugins.push('@babel/plugin-proposal-class-properties'); - }) - - // enables @babel/preset-env polyfills - .configureBabelPresetEnv((config) => { - config.useBuiltIns = 'usage'; - config.corejs = 3; - }) - .enablePostCssLoader() - .enableSassLoader() - ; - // build the second configuration - const themeConfig = Encore.getWebpackConfig(); +module.exports = Encore.getWebpackConfig(); - // Set a unique name for the config (needed later!) - themeConfig.name = 'themeConfig'; - -; -// export the final configuration as an array of multiple configurations -module.exports = [appConfig, themeConfig];