-
-
Notifications
You must be signed in to change notification settings - Fork 486
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
Pefixing all Stimulus-related files with stimulus_
#1022
Conversation
ThomasLandauer
commented
Nov 9, 2021
Q | A |
---|---|
License | MIT |
Doc issue/PR | symfony/webpack-encore-bundle#150 |
Thanks for the PR 😍 How to test these changes in your application
Diff between recipe versionsIn order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes. symfony/webpack-encore-bundle1.0 vs 1.6diff --git a/symfony/webpack-encore-bundle/1.6/config/packages/test/webpack_encore.yaml b/symfony/webpack-encore-bundle/1.6/config/packages/test/webpack_encore.yaml
new file mode 100644
index 0000000..02a7651
--- /dev/null
+++ b/symfony/webpack-encore-bundle/1.6/config/packages/test/webpack_encore.yaml
@@ -0,0 +1,2 @@
+#webpack_encore:
+# strict_mode: false
diff --git a/symfony/webpack-encore-bundle/1.0/config/packages/webpack_encore.yaml b/symfony/webpack-encore-bundle/1.6/config/packages/webpack_encore.yaml
index ce02f6b..a1335c5 100644
--- a/symfony/webpack-encore-bundle/1.0/config/packages/webpack_encore.yaml
+++ b/symfony/webpack-encore-bundle/1.6/config/packages/webpack_encore.yaml
@@ -1,14 +1,25 @@
webpack_encore:
- # The path where Encore is building the assets.
- # This should match Encore.setOutputPath() in webpack.config.js.
+ # 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
- # if using Encore.enableIntegrityHashes() specify the crossorigin attribute value (default: false, or use 'anonymous' or 'use-credentials')
+ # If using Encore.enableIntegrityHashes() and need the crossorigin attribute (default: false, or use 'anonymous' or 'use-credentials')
# crossorigin: 'anonymous'
- # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes).
- # To enable caching for the production environment, creating a webpack_encore.yaml in the config/packages/prod directory with this value set to true
- # Available in version 1.2
- #cache: false
+ # 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:
+ # pass "frontend" as the 3rg arg to the Twig functions
+ # {{ encore_entry_script_tags('entry1', null, 'frontend') }}
+
+ # frontend: '%kernel.project_dir%/public/frontend/build'
+
+ # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
+ # Put in config/packages/prod/webpack_encore.yaml
+ # cache: true 1.6 vs 1.9diff --git a/symfony/webpack-encore-bundle/1.6/assets/app.js b/symfony/webpack-encore-bundle/1.9/assets/app.js
index bb0a6aa..64dfbe2 100644
--- a/symfony/webpack-encore-bundle/1.6/assets/app.js
+++ b/symfony/webpack-encore-bundle/1.9/assets/app.js
@@ -9,4 +9,4 @@
import './styles/app.css';
// start the Stimulus application
-import './bootstrap';
+import './stimulus_bootstrap';
diff --git a/symfony/webpack-encore-bundle/1.6/assets/bootstrap.js b/symfony/webpack-encore-bundle/1.9/assets/stimulus_bootstrap.js
similarity index 81%
rename from symfony/webpack-encore-bundle/1.6/assets/bootstrap.js
rename to symfony/webpack-encore-bundle/1.9/assets/stimulus_bootstrap.js
index 58308a6..0960e6c 100644
--- a/symfony/webpack-encore-bundle/1.6/assets/bootstrap.js
+++ b/symfony/webpack-encore-bundle/1.9/assets/stimulus_bootstrap.js
@@ -2,7 +2,7 @@ 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',
+ '@symfony/stimulus-bridge/lazy-controller-loader!./stimulus_controllers',
true,
/\.(j|t)sx?$/
));
diff --git a/symfony/webpack-encore-bundle/1.6/assets/controllers/hello_controller.js b/symfony/webpack-encore-bundle/1.9/assets/stimulus_controllers/hello_controller.js
similarity index 55%
rename from symfony/webpack-encore-bundle/1.6/assets/controllers/hello_controller.js
rename to symfony/webpack-encore-bundle/1.9/assets/stimulus_controllers/hello_controller.js
index 8c79f65..076bc81 100644
--- a/symfony/webpack-encore-bundle/1.6/assets/controllers/hello_controller.js
+++ b/symfony/webpack-encore-bundle/1.9/assets/stimulus_controllers/hello_controller.js
@@ -3,14 +3,15 @@ import { Controller } from '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:
+ * Any HTML element with a data-controller="hello" attribute will cause this controller to be executed. Example:
+ * <div data-controller="hello"></div>
+ * 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';
+ this.element.textContent = 'Hello Stimulus! Edit me in assets/stimulus_controllers/hello_controller.js';
}
}
diff --git a/symfony/webpack-encore-bundle/1.6/assets/controllers.json b/symfony/webpack-encore-bundle/1.9/assets/stimulus_controllers.json
similarity index 100%
rename from symfony/webpack-encore-bundle/1.6/assets/controllers.json
rename to symfony/webpack-encore-bundle/1.9/assets/stimulus_controllers.json
diff --git a/symfony/webpack-encore-bundle/1.6/config/packages/webpack_encore.yaml b/symfony/webpack-encore-bundle/1.9/config/packages/webpack_encore.yaml
index a1335c5..fa2e39d 100644
--- a/symfony/webpack-encore-bundle/1.6/config/packages/webpack_encore.yaml
+++ b/symfony/webpack-encore-bundle/1.9/config/packages/webpack_encore.yaml
@@ -4,6 +4,16 @@ webpack_encore:
# 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'
diff --git a/symfony/webpack-encore-bundle/1.9/post-install.txt b/symfony/webpack-encore-bundle/1.9/post-install.txt
new file mode 100644
index 0000000..735ed3e
--- /dev/null
+++ b/symfony/webpack-encore-bundle/1.9/post-install.txt
@@ -0,0 +1,5 @@
+ * Install Yarn and run yarn install
+
+ * Uncomment the Twig helpers in templates/base.html.twig
+
+ * Start the development server: yarn encore dev-server
diff --git a/symfony/webpack-encore-bundle/1.6/webpack.config.js b/symfony/webpack-encore-bundle/1.9/webpack.config.js
index 056b04a..b57f3fc 100644
--- a/symfony/webpack-encore-bundle/1.6/webpack.config.js
+++ b/symfony/webpack-encore-bundle/1.9/webpack.config.js
@@ -23,7 +23,7 @@ Encore
.addEntry('app', './assets/app.js')
// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
- .enableStimulusBridge('./assets/controllers.json')
+ .enableStimulusBridge('./assets/stimulus_controllers.json')
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
.splitEntryChunks() |
@@ -23,7 +23,7 @@ Encore | |||
.addEntry('app', './assets/app.js') | |||
|
|||
// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js) | |||
.enableStimulusBridge('./assets/controllers.json') |
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.
This assets/controllers.json
file is managed by Flex, so you cannot rename it here.
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.
OK. So what can I do?
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.
Well, either not renaming the controllers.json file, or first building a way to make this filename configurable in Flex to allow new projects to use the new name while existing projects would still use assets/controllers.json
until they migrate.
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.
Migrate? I was thinking these recipes here are a one-time installation "helper", and this is (more or less) what's called "Flex" ;-) But obviously there's more to it... So where is this Flex-thing ;-) configured?
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.
Flex is composer plugin, that installs recipes and manages a few files automatically (config/bundles.php
and assets/controllers.json
)
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.
Thanks! It's coming from this line: https://github.com/symfony/flex/blob/main/src/PackageJsonSynchronizer.php#L111
So in order to make this change, both repos need to be updated simultaneously?
For existing users it shouldn't make a difference, cause the path in .enableStimulusBridge()
(in webpack.config.js
) overrides, right?
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.
Well, for existing users, they need their Flex plugin to keep managing the assets/controllers.json
file until the time they rename it. That's why I said it needs a migration strategy for the Flex plugin.
After thinking some more about it, I'm now suggesting: Why: So I'm suggesting:
The result would be:
|
I would be ok with renaming to I don't like renaming I DO want to continue installing this by default. The benefits outweigh negatives, and making a change like this also invalidates documentation, screencasts & people's existing knowledge of how it works. In other words, change has cost, so it needs to be worth it. |
The more I think about it, the more absurd this seems to me!
No, cause there is none! ;-) This makes matters even worse! Instead of telling people:
.. the documentation says: NOTHING. Nothing about what Stimulus is, nothing about installation, nothing about uninstallation, nothing about possible problems. In my case, Stimulus broke the installation of Webpack Encore, so I ended up opening an issue at symfony/stimulus-bridge#49
Anybody who already knows how it works is already using it. So they're not affected if it's not installed by default anymore for future users. Finally: @weaverryan, thanks a lot for https://symfonycasts.com/screencast/stimulus/controllers ! If this didn't exist, I'll probably still be searching today... ;-)
But maybe I should have asked another question first ;-) What are the benefits of installing it by default? |
Very fair critique. This is a huge problem.
This is unfortunate, but it's a temporary issue. We need to release v3 support - it's ready. But I want to release one more 1.x symfony/ux release that supports Symfony 6 first (waiting on symfony/panther to add support first).
Developer experience ;). Our hope is that most people that are starting new projects WILL use Stimulus, and then it's already setup and ready for them. Nobody knows what percentage really do, so it's a guessing game. Also, there is not a mechanism in Flex to add these files other than through WebpackEncoreBundle's recipe. So installation would mean copying a few files manually. Not a huge deal - but I still think we should keep it. We should fix (add) documentation and get our Stimulus v3 release done. That would have prevented the problems in the first place. We don't need to blow up the system because of the bumps :). |
You mean it's not possible to enable installation in the "usual" way, by doing something like Let's get a clear picture which files we're talking about:
My opinion about them:
So what I'm suggesting:
|
To "fix" symfony/stimulus-bridge#47, there should be the expected |
Please be careful - we are not trying to trick anyone. Let's please keep the language objective and constructive :).
You're correct about this, of course. But I don't understand what you mean to say. The WebpackEncoreBundle gives you that package.json, so you should always have Overall, I think your points are indeed valid. However, I still disagree in the final conclusion. The goal is to streamline the "main" experience. That includes people being able to install WebpackEncoreBundle and then install UX packages and have them work. Commenting files out or removing them entirely is going to make it more possible that we break this workflow. So, let's try to find something that we can agree to fix :). I can think of a few, some are obvious: A) We need to get the Stimulus v3 support done and taagged! recipes/symfony/webpack-encore-bundle/1.9/assets/app.js Lines 11 to 12 in a624d3b
bootstrap_stimulus.js .
By the way, I need to check, but I think if you comment-out |
Well, you're installing a software on my machine without telling me. How would you call that? So what I'd suggest (and I could do) is: |
This narrative that suggests there are nasty intentions embedded in the code makes it very unpleasant to review this discussion. @ThomasLandauer I feel like you're try to say that we should consider decoupling webpack-encore-bundle from symfony-ux but please seriously reconsider the way you express your point. |
I asked three times if it's OK if I add some documentation, but didn't get an answer. So I'm giving up now. Sorry for having bothered you at all! |
A day later, let me express my point of view: When I first questioned the current practice, you said:
OK. Then, when I used more drastic words to convince you that what you're doing is a problem, you said:
OK. Finally, combining the fact that you didn't merge symfony/symfony-docs#14499 in more than a year, with my impression that you're seeing me as not "constructive", then I'm sure you can guess how "high" my motivation is to put more effort in here. So since you're not seeing as a problem what I'm seeing as the main problem, I don't want to continue being the bad boy who questions your decisions. |
These are the words you used in this discussion and that made us ask you to keep things cool, because nobody can feel comfortable with such an atmosphere. @weaverryan did try to understand you concerns, despite the tone. Please acknowledge that.
I'm not looking at the doc repo very closely, sorry about that. Other ppl could have chimed into this PR instead of me, but that didn't happen. This has nothing to do with you. And yes, the words I listed above don't contribute to the constructive part of the discussion. I might be wrong but interpret them as expression of frustration, because you really want us to understand your point and you fear we might not. On my side, and I suppose on yours and Ryan's too, we need a peaceful atmosphere to best engage into discussions.
We (Ryan mostly) are trying to understand the problem you're raising, but we also don't want to sacrifice the core reasons that made us build things the way they are today. We should be all trying to understand how to fix ones' problem without negating the other side's problem. Your help on this path is very much appreciated. There is no good or "bad boy". Our past decisions always remain open for discussion. |
Well, thanks for answering! I'm always trying to see it from the users' perspective. What would you say if you'd type And I couldn't believe that you didn't instantly agree that doing it this way is not good. That's why I was using some (maybe too) harsh words. But I certainly didn't want to offend or insult you or anybody else - sorry about that! So answering your question from above:
I don't know what Symfony UX is exactly, but "decoupling" sounds very good! :-) How could this be achieved? Cause Ryan said above:
This means, that doing it the usual way with something like If yes, I see two options:
In any case, we all agree that documentation is needed. I think (contrary to what I said above) the best place is a dedicated Stimulus page listed at https://symfony.com/doc/current/frontend.html#other-front-end-articles
...then I'd say the best way is to (a) add a note from composer/flex after installation, and/or (b) mention it at https://symfony.com/doc/current/frontend/encore/installation.html |