Skip to content

Commit 577e35e

Browse files
Scottjaviereguiluz
Scott
authored andcommitted
Changing the wording around module.exports
Hello! I just want to point something out here: Using the commonjs format (require() and module.exports, though node does add some additional things on top of that spec) *is not* the same, or even roughly the same, which is implied/stated by this line here: >Instead of using require and module.exports like shown above, JavaScript has an alternate syntax, which is a more accepted standard. Choose whichever you want: they do the same thing. I propose a minor edit here, which is that we actually want to clarify that the ECMAScript standard that has been finalized (often this is known as ES6 or ES2015. There was a minor revision in there but thats long since passed in either case) and one of the purposes, per the Module spec, is that this is the standard for which modules will be *native to the browser*. (In the evergreen versions of Safari, Chrome, Firefox, and I think even Edge now, you can use `<script type="module" src="somemodule.js">` and it will work fine). They are also the only official way of using dynamic imports, as highlighted [in your own documentation](https://symfony.com/doc/current/frontend/encore/code-splitting.html) in a way that I think gets the point across very well. I think this is very misleading otherwise. You do in fact see a performance decoupling bundling the commonjs modules, as webpack can't take advantage of code splitting with dynamic imports without using ECMAScript modules (more or less, from a high level view). Of course I'm okay changing whatever wording as needed, but I think we should really point out that require() and import are two *very* different beasts, and I am happy to write up as to way, give links, etc.
1 parent 9b7f158 commit 577e35e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

frontend/encore/simple-example.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ The import and export Statements
180180
--------------------------------
181181

182182
Instead of using ``require`` and ``module.exports`` like shown above, JavaScript
183-
has an alternate syntax, which is a more accepted standard. Choose whichever you
184-
want: they do the same thing.
183+
has an alternate syntax, which is the new finalized ECMAScript standard for using modules in the browser, including
184+
the ability to use dynamic imports
185+
186+
..
185187
186188
To export values, use ``exports``:
187189

@@ -333,8 +335,7 @@ If you want to only compile a CSS file, that's possible via ``addStyleEntry()``:
333335
Encore
334336
// ...
335337
336-
.addStyleEntry('some_page', './assets/css/some_page.css')
337-
;
338+
.addStyleEntry('some_page', './assets/css/some_page.css');
338339
339340
This will output a new ``some_page.css``.
340341

0 commit comments

Comments
 (0)