From a91c2d7389b0c3ee95663c4f880155905a50bae3 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Thu, 16 Oct 2025 21:39:35 +0200 Subject: [PATCH] [WebpackEncoreBundle] Add recipe for old version 1.17, adjust @symfony/stimulus-bridge constraints --- .../webpack-encore-bundle/1.10/package.json | 2 +- .../webpack-encore-bundle/1.17/assets/app.js | 12 +++ .../1.17/assets/bootstrap.js | 11 +++ .../1.17/assets/controllers.json | 4 + .../assets/controllers/hello_controller.js | 16 ++++ .../1.17/assets/styles/app.css | 3 + .../1.17/config/packages/webpack_encore.yaml | 45 +++++++++++ .../webpack-encore-bundle/1.17/manifest.json | 21 +++++ .../webpack-encore-bundle/1.17/package.json | 22 ++++++ .../1.17/post-install.txt | 3 + .../1.17/webpack.config.js | 76 +++++++++++++++++++ .../webpack-encore-bundle/1.9/package.json | 2 +- .../webpack-encore-bundle/2.0/package.json | 2 +- 13 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 symfony/webpack-encore-bundle/1.17/assets/app.js create mode 100644 symfony/webpack-encore-bundle/1.17/assets/bootstrap.js create mode 100644 symfony/webpack-encore-bundle/1.17/assets/controllers.json create mode 100644 symfony/webpack-encore-bundle/1.17/assets/controllers/hello_controller.js create mode 100644 symfony/webpack-encore-bundle/1.17/assets/styles/app.css create mode 100644 symfony/webpack-encore-bundle/1.17/config/packages/webpack_encore.yaml create mode 100644 symfony/webpack-encore-bundle/1.17/manifest.json create mode 100644 symfony/webpack-encore-bundle/1.17/package.json create mode 100644 symfony/webpack-encore-bundle/1.17/post-install.txt create mode 100644 symfony/webpack-encore-bundle/1.17/webpack.config.js diff --git a/symfony/webpack-encore-bundle/1.10/package.json b/symfony/webpack-encore-bundle/1.10/package.json index 360272aa0..ad2eb752c 100644 --- a/symfony/webpack-encore-bundle/1.10/package.json +++ b/symfony/webpack-encore-bundle/1.10/package.json @@ -3,7 +3,7 @@ "@babel/core": "^7.17.0", "@babel/preset-env": "^7.16.0", "@hotwired/stimulus": "^3.0.0", - "@symfony/stimulus-bridge": "^4.0.0", + "@symfony/stimulus-bridge": "^3.0.0", "@symfony/webpack-encore": "^4.0.0", "core-js": "^3.23.0", "regenerator-runtime": "^0.13.9", diff --git a/symfony/webpack-encore-bundle/1.17/assets/app.js b/symfony/webpack-encore-bundle/1.17/assets/app.js new file mode 100644 index 000000000..bb0a6aa13 --- /dev/null +++ b/symfony/webpack-encore-bundle/1.17/assets/app.js @@ -0,0 +1,12 @@ +/* + * Welcome to your app's main JavaScript file! + * + * We recommend including the built version of this JavaScript file + * (and its CSS file) in your base layout (base.html.twig). + */ + +// any CSS you import will output into a single css file (app.css in this case) +import './styles/app.css'; + +// start the Stimulus application +import './bootstrap'; diff --git a/symfony/webpack-encore-bundle/1.17/assets/bootstrap.js b/symfony/webpack-encore-bundle/1.17/assets/bootstrap.js new file mode 100644 index 000000000..4ab2df643 --- /dev/null +++ b/symfony/webpack-encore-bundle/1.17/assets/bootstrap.js @@ -0,0 +1,11 @@ +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, + /\.[jt]sx?$/ +)); + +// register any custom, 3rd party controllers here +// app.register('some_controller_name', SomeImportedController); diff --git a/symfony/webpack-encore-bundle/1.17/assets/controllers.json b/symfony/webpack-encore-bundle/1.17/assets/controllers.json new file mode 100644 index 000000000..a1c6e90cf --- /dev/null +++ b/symfony/webpack-encore-bundle/1.17/assets/controllers.json @@ -0,0 +1,4 @@ +{ + "controllers": [], + "entrypoints": [] +} diff --git a/symfony/webpack-encore-bundle/1.17/assets/controllers/hello_controller.js b/symfony/webpack-encore-bundle/1.17/assets/controllers/hello_controller.js new file mode 100644 index 000000000..e847027bd --- /dev/null +++ b/symfony/webpack-encore-bundle/1.17/assets/controllers/hello_controller.js @@ -0,0 +1,16 @@ +import { Controller } from '@hotwired/stimulus'; + +/* + * This is an example Stimulus controller! + * + * Any element with a data-controller="hello" attribute will cause + * this controller to be executed. The name "hello" comes from the filename: + * hello_controller.js -> "hello" + * + * Delete this file or adapt it for your use! + */ +export default class extends Controller { + connect() { + this.element.textContent = 'Hello Stimulus! Edit me in assets/controllers/hello_controller.js'; + } +} diff --git a/symfony/webpack-encore-bundle/1.17/assets/styles/app.css b/symfony/webpack-encore-bundle/1.17/assets/styles/app.css new file mode 100644 index 000000000..cb33b1315 --- /dev/null +++ b/symfony/webpack-encore-bundle/1.17/assets/styles/app.css @@ -0,0 +1,3 @@ +body { + background-color: lightgray; +} diff --git a/symfony/webpack-encore-bundle/1.17/config/packages/webpack_encore.yaml b/symfony/webpack-encore-bundle/1.17/config/packages/webpack_encore.yaml new file mode 100644 index 000000000..4c009ee49 --- /dev/null +++ b/symfony/webpack-encore-bundle/1.17/config/packages/webpack_encore.yaml @@ -0,0 +1,45 @@ +webpack_encore: + # The path where Encore is building the assets - i.e. Encore.setOutputPath() + output_path: '%kernel.project_dir%/public/build' + # If multiple builds are defined (as shown below), you can disable the default build: + # output_path: false + + # 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') }} + +framework: + assets: + json_manifest_path: '%kernel.project_dir%/public/build/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/symfony/webpack-encore-bundle/1.17/manifest.json b/symfony/webpack-encore-bundle/1.17/manifest.json new file mode 100644 index 000000000..39b0363ea --- /dev/null +++ b/symfony/webpack-encore-bundle/1.17/manifest.json @@ -0,0 +1,21 @@ +{ + "bundles": { + "Symfony\\WebpackEncoreBundle\\WebpackEncoreBundle": ["all"] + }, + "copy-from-recipe": { + "assets/": "assets/", + "config/": "%CONFIG_DIR%/", + "package.json": "package.json", + "webpack.config.js": "webpack.config.js" + }, + "aliases": ["encore", "webpack", "webpack-encore"], + "gitignore": [ + "/node_modules/", + "/%PUBLIC_DIR%/build/", + "npm-debug.log", + "yarn-error.log" + ], + "conflict": { + "symfony/framework-bundle": "<5.4" + } +} diff --git a/symfony/webpack-encore-bundle/1.17/package.json b/symfony/webpack-encore-bundle/1.17/package.json new file mode 100644 index 000000000..e41187286 --- /dev/null +++ b/symfony/webpack-encore-bundle/1.17/package.json @@ -0,0 +1,22 @@ +{ + "devDependencies": { + "@babel/core": "^7.17.0", + "@babel/preset-env": "^7.16.0", + "@hotwired/stimulus": "^3.0.0", + "@symfony/stimulus-bridge": "^4.0.0", + "@symfony/webpack-encore": "^5.1.0", + "core-js": "^3.23.0", + "regenerator-runtime": "^0.13.9", + "webpack": "^5.74.0", + "webpack-cli": "^4.10.0", + "webpack-notifier": "^1.15.0" + }, + "license": "UNLICENSED", + "private": true, + "scripts": { + "dev-server": "encore dev-server", + "dev": "encore dev", + "watch": "encore dev --watch", + "build": "encore production --progress" + } +} diff --git a/symfony/webpack-encore-bundle/1.17/post-install.txt b/symfony/webpack-encore-bundle/1.17/post-install.txt new file mode 100644 index 000000000..e53f05dc4 --- /dev/null +++ b/symfony/webpack-encore-bundle/1.17/post-install.txt @@ -0,0 +1,3 @@ + * Install Yarn and run yarn install + + * Start the development server: yarn encore dev-server diff --git a/symfony/webpack-encore-bundle/1.17/webpack.config.js b/symfony/webpack-encore-bundle/1.17/webpack.config.js new file mode 100644 index 000000000..408012fa4 --- /dev/null +++ b/symfony/webpack-encore-bundle/1.17/webpack.config.js @@ -0,0 +1,76 @@ +const Encore = require('@symfony/webpack-encore'); + +// Manually configure the runtime environment if not already configured yet by the "encore" command. +// It's useful when you use tools that rely on webpack.config.js file. +if (!Encore.isRuntimeEnvironmentConfigured()) { + Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev'); +} + +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 subdirectory deploy + //.setManifestKeyPrefix('build/') + + /* + * ENTRY CONFIG + * + * Each entry will result in one JavaScript file (e.g. app.js) + * and one CSS file (e.g. app.css) if your JavaScript imports CSS. + */ + .addEntry('app', './assets/app.js') + + // enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js) + .enableStimulusBridge('./assets/controllers.json') + + // When enabled, Webpack "splits" your files into smaller pieces for greater optimization. + .splitEntryChunks() + + // will require an extra script tag for runtime.js + // but, you probably want this, unless you're building a single-page app + .enableSingleRuntimeChunk() + + /* + * FEATURE CONFIG + * + * Enable & configure other features below. For a full + * list of features, see: + * https://symfony.com/doc/current/frontend.html#adding-more-features + */ + .cleanupOutputBeforeBuild() + .enableBuildNotifications() + .enableSourceMaps(!Encore.isProduction()) + // enables hashed filenames (e.g. app.abc123.css) + .enableVersioning(Encore.isProduction()) + + // configure Babel + // .configureBabel((config) => { + // config.plugins.push('@babel/a-babel-plugin'); + // }) + + // enables and configure @babel/preset-env polyfills + .configureBabelPresetEnv((config) => { + config.useBuiltIns = 'usage'; + config.corejs = '3.23'; + }) + + // enables Sass/SCSS support + //.enableSassLoader() + + // uncomment if you use TypeScript + //.enableTypeScriptLoader() + + // uncomment if you use React + //.enableReactPreset() + + // uncomment to get integrity="..." attributes on your script & link tags + // requires WebpackEncoreBundle 1.4 or higher + //.enableIntegrityHashes(Encore.isProduction()) + + // uncomment if you're having problems with a jQuery plugin + //.autoProvidejQuery() +; + +module.exports = Encore.getWebpackConfig(); diff --git a/symfony/webpack-encore-bundle/1.9/package.json b/symfony/webpack-encore-bundle/1.9/package.json index 820342883..813010a74 100644 --- a/symfony/webpack-encore-bundle/1.9/package.json +++ b/symfony/webpack-encore-bundle/1.9/package.json @@ -1,7 +1,7 @@ { "devDependencies": { "@hotwired/stimulus": "^3.0.0", - "@symfony/stimulus-bridge": "^4.0.0", + "@symfony/stimulus-bridge": "^3.0.0", "@symfony/webpack-encore": "^1.7.0", "core-js": "^3.0.0", "regenerator-runtime": "^0.13.2", diff --git a/symfony/webpack-encore-bundle/2.0/package.json b/symfony/webpack-encore-bundle/2.0/package.json index d34029031..6e94b1654 100644 --- a/symfony/webpack-encore-bundle/2.0/package.json +++ b/symfony/webpack-encore-bundle/2.0/package.json @@ -2,7 +2,7 @@ "devDependencies": { "@babel/core": "^7.17.0", "@babel/preset-env": "^7.16.0", - "@symfony/webpack-encore": "^5.0.0", + "@symfony/webpack-encore": "^5.1.0", "core-js": "^3.38.0", "regenerator-runtime": "^0.13.9", "webpack": "^5.74.0",