Skip to content

Commit c247131

Browse files
authored
Merge pull request #324 from symfony/webpack4
Hello Webpack4 ⭐️
2 parents 63e15ce + ab109cd commit c247131

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4015
-2755
lines changed

.travis.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ cache:
99
matrix:
1010
include:
1111
- os: linux
12-
node_js: "7"
12+
node_js: "10"
1313
env: JOB_PART=travis:lint
1414
- os: linux
15-
node_js: "8"
15+
node_js: "10"
16+
env: JOB_PART=test
17+
- os: linux
18+
node_js: "9"
1619
env: JOB_PART=test
1720
- os: linux
18-
node_js: "7"
21+
node_js: "8"
1922
env: JOB_PART=test
2023
- os: linux
2124
node_js: "6"

CHANGELOG.md

+80
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,85 @@
11
# CHANGELOG
22

3+
## 0.21.0 Webpack 4 Upgrade
4+
5+
* [BC BREAK] Webpack was upgraded to version 4. This includes a number of major
6+
and minor changes. The changes are listed below.
7+
8+
* [DEPRECATION] You must now call either `Encore.enableSingleRuntimeChunk()`
9+
or `Encore.disableSingleRuntimeChunk()`: not calling either method is
10+
deprecated. The recommended setting is `Encore.enableSingleRuntimeChunk()`.
11+
This will cause a new `runtime.js` file to be created, which must be included
12+
on your page with a script tag (before any other script tags for Encore
13+
JavaScript files). See the documentation above `enableSingleRuntimeChunk()` in
14+
`index.js` for more details.
15+
16+
* [BEHAVIOR CHANGE] Previously, without any config, Babel was
17+
configured to "transpile" (i.e. re-write) your JavaScript so
18+
that it was compatible with all browsers that currently have
19+
more than 1% of the market share. The new default behavior
20+
is a bit more aggressive, and may rewrite even more code to
21+
be compatible with even older browsers. The *recommendation*
22+
is to add a new `browserslist` key to your `package.json` file
23+
that specifies exactly what browsers you need to support. For
24+
example, to get the old configuration, add the following to
25+
`package.json`:
26+
27+
```json
28+
{
29+
"browserslist": "> 1%"
30+
}
31+
```
32+
33+
See the [browserslist](https://github.com/browserslist/browserslist) library
34+
for a full description of all of the valid browser descriptions.
35+
36+
* Node 7 is no longer supported. This is because the new
37+
`mini-css-extract-plugin` does not support it (and neither)
38+
does Yarn.
39+
40+
* Introduced a new `configureSplitChunks()` method that can be
41+
used to further configure the `optimizations.splitChunks` configuration.
42+
43+
* A new `entrypoints.json` file is now always output. For expert
44+
use-cases, the `optimizations.splitChunks.chunks` configuration
45+
can be set via `configureSplitChunks()` to `all`. Then, you
46+
can write some custom server-side code to parse the `entrypoints.js`
47+
so that you know which `script` and `link` tags are needed for
48+
each entry.
49+
50+
* The "dynamic import" syntax is now supported out of the box
51+
because the `@babel/plugin-syntax-dynamic-import` babel plugin
52+
is always enabled. This allows you to do "Dynamic Imports"
53+
as described here: https://webpack.js.org/guides/code-splitting/#dynamic-imports
54+
55+
* For Preact, the necessary plugin the user needs to install
56+
changed from `babel-plugin-transform-react-jsx` to `@babel/plugin-transform-react-jsx`.
57+
58+
* The NamedModulesPlugin was removed.
59+
60+
* The `babel-preset-env` package (which was at version ^1.2.2) was
61+
removed in favor of `@babel/preset-env`.
62+
63+
* ExtractTextPlugin was removed and replaced with
64+
mini-css-extract-plugin. Accordingly, `extractTextPluginOptionsCallback()`
65+
was removed.
66+
67+
* Support for CoffeeScript was entirely removed.
68+
69+
* A new "version check" system was added for optional dependencies.
70+
Now, when you install optional plugins to support a feature, if
71+
you are using an unsupported version, you will see a warning.
72+
"Package recommendation" errors (i.e. when you enable a feature
73+
but you are missing some packages) will also contain the version
74+
in the install string when necessary (e.g. `yarn add foo@^2.0`).
75+
76+
* Actual lang="sass" no longer works for Vue. However, lang="scss"
77+
continues to work fine.
78+
79+
* uglifyjs-webpack-plugin was upgraded from 0.4.6 to 1.2.5, which
80+
includes using `uglify-es`. If you're using `configureUglifyJsPlugin`(),
81+
the options have changed.
82+
383
## 0.20.1
484

585
* Upgraded webpack-manifest-plugin from 2.0.0 RC1 to ^2.0.0.

bin/encore.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@
1313
const parseRuntime = require('../lib/config/parse-runtime');
1414
const context = require('../lib/context');
1515
const chalk = require('chalk');
16+
const logger = require('../lib/logger');
1617

1718
const runtimeConfig = parseRuntime(
1819
require('yargs/yargs')(process.argv.slice(2)).argv,
1920
process.cwd()
2021
);
2122
context.runtimeConfig = runtimeConfig;
2223

23-
// remove the command from the output
24+
// prevent logs from being dumped
25+
if (runtimeConfig.outputJson) {
26+
logger.quiet();
27+
}
28+
29+
// remove the command from the input
2430
process.argv.splice(2, 1);
2531

2632
if (!runtimeConfig.isValidCommand) {

fixtures/js/append_to_app.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
document.getElementById('app').innerHTML = document.getElementById('app').innerHTML + 'Welcome to Encore!';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// use code splitting via a dynamic import
2+
import('./print_to_app_export').then(printToApp => {
3+
printToApp.default();
4+
});

fixtures/js/index.coffee

-4
This file was deleted.

fixtures/js/print_to_app.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
document.getElementById('app').innerHTML = 'Welcome to Encore!';

fixtures/js/print_to_app_export.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function() {
2+
document.getElementById('app').innerHTML = 'Welcome to Encore!';
3+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./arrow_function');

fixtures/js/shared_example.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// used in a createdSharedEntry() test
2+
require('./no_require');
3+
require('./requires_arrow_function');
4+
require('./../css/h1_style.css');
5+
require('./print_to_app');

fixtures/vuejs/App.vue

-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ export default {
3838
}
3939
</style>
4040

41-
<style lang="sass">
42-
#app
43-
color: #2c3e90
44-
</style>
45-
4641
<style lang="less">
4742
#app {
4843
margin-top: 40px;

index.js

+112-48
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,6 @@ class Encore {
123123
return this;
124124
}
125125

126-
/**
127-
* Allows you to configure the options passed to the extract-text-webpack-plugin.
128-
* A list of available options can be found at https://github.com/webpack-contrib/extract-text-webpack-plugin
129-
*
130-
* For example:
131-
*
132-
* Encore.configureExtractTextPlugin((options) => {
133-
* options.ignoreOrder = true;
134-
* })
135-
*
136-
* @param {function} extractTextPluginOptionsCallback
137-
* @returns {Encore}
138-
*/
139-
configureExtractTextPlugin(extractTextPluginOptionsCallback = () => {}) {
140-
webpackConfig.configureExtractTextPlugin(extractTextPluginOptionsCallback);
141-
142-
return this;
143-
}
144-
145126
/**
146127
* Allows you to configure the options passed to the friendly-errors-webpack-plugin.
147128
* A list of available options can be found at https://github.com/geowarin/friendly-errors-webpack-plugin
@@ -201,13 +182,17 @@ class Encore {
201182

202183
/**
203184
* Allows you to configure the options passed to the uglifyjs-webpack-plugin.
204-
* A list of available options can be found at https://github.com/webpack-contrib/uglifyjs-webpack-plugin/tree/v0.4.6
185+
* A list of available options can be found at https://github.com/webpack-contrib/uglifyjs-webpack-plugin
205186
*
206187
* For example:
207188
*
208189
* Encore.configureUglifyJsPlugin((options) => {
209-
* options.compress = false;
210-
* options.beautify = true;
190+
* options.cache = true;
191+
* options.uglifyOptions = {
192+
* output: {
193+
* comments: false
194+
* }
195+
* }
211196
* })
212197
*
213198
* @param {function} uglifyJsPluginOptionsCallback
@@ -225,7 +210,7 @@ class Encore {
225210
* // final output file will be main.js in the output directory
226211
* Encore.addEntry('main', './path/to/some_file.js');
227212
*
228-
* If the JavaScript file imports/requires CSS/SASS/LESS files,
213+
* If the JavaScript file imports/requires CSS/Sass/LESS files,
229214
* then a CSS file (e.g. main.css) will also be output.
230215
*
231216
* @param {string} name The name (without extension) that will be used
@@ -407,14 +392,98 @@ class Encore {
407392
}
408393

409394
/**
410-
* Add a "commons" file that holds JS shared by multiple chunks.
395+
* Add a "commons" file that holds JS shared by multiple chunks/files.
411396
*
412397
* @param {string} name The chunk name (e.g. vendor to create a vendor.js)
413-
* @param {string|Array} files Array of files to put in the vendor entry
398+
* @param {string} file A file whose code & imports should be put into the shared file.
414399
* @returns {Encore}
415400
*/
416-
createSharedEntry(name, files) {
417-
webpackConfig.createSharedEntry(name, files);
401+
createSharedEntry(name, file) {
402+
webpackConfig.createSharedEntry(name, file);
403+
404+
return this;
405+
}
406+
407+
/**
408+
* Tell Webpack to output a separate runtime.js file.
409+
*
410+
* This file must be included via a script tag before all
411+
* other JavaScript files output by Encore.
412+
*
413+
* The runtime.js file is useful when you plan to include
414+
* multiple entry files on the same page (e.g. a layout.js entry
415+
* and a page-specific entry). If you are *not* including
416+
* multiple entries on the same page, you can safely disable
417+
* this - disableSingleRuntimeChunk() - and remove the extra script tags.
418+
*
419+
* If you *do* include multiple entry files on the same page,
420+
* disabling the runtime.js file has two important consequences:
421+
* A) Each entry file will contain the Webpack runtime, which
422+
* means each contains some code that is duplicated in the other.
423+
* B) If two entry files require the same module (e.g. jquery),
424+
* they will receive *different* objects - not the *same* object.
425+
* This can cause some confusion if you expect a "layout.js" entry
426+
* to be able to "initialize" some jQuery plugins, because the
427+
* jQuery required by the other entry will be a different instance,
428+
* and so won't have the plugins initialized on it.
429+
*
430+
* @returns {Encore}
431+
*/
432+
enableSingleRuntimeChunk() {
433+
webpackConfig.enableSingleRuntimeChunk();
434+
435+
return this;
436+
}
437+
438+
/**
439+
* Tell Webpack to *not* output a separate runtime.js file.
440+
*
441+
* See enableSingleRuntimeChunk() for more details.
442+
*
443+
* @returns {Encore}
444+
*/
445+
disableSingleRuntimeChunk() {
446+
webpackConfig.disableSingleRuntimeChunk();
447+
448+
return this;
449+
}
450+
451+
/**
452+
* Tell Webpack to "split" your entry chunks.
453+
*
454+
* This will mean that, instead of adding 1 script tag
455+
* to your page, your server-side code will need to read
456+
* the entrypoints.json file in the build directory to
457+
* determine the *multiple* .js (and .css) files that
458+
* should be included for each entry.
459+
*
460+
* This is a performance optimization, but requires extra
461+
* work (described above) to support this.
462+
*
463+
* @returns {Encore}
464+
*/
465+
splitEntryChunks() {
466+
webpackConfig.splitEntryChunks();
467+
468+
return this;
469+
}
470+
471+
/**
472+
* Configure the optimization.splitChunks configuration.
473+
*
474+
* https://webpack.js.org/plugins/split-chunks-plugin/
475+
*
476+
* Encore.configureSplitChunks(function(splitChunks) {
477+
* // change the configuration
478+
*
479+
* splitChunks.minSize = 0;
480+
* });
481+
*
482+
* @param {function} callback
483+
* @returns {Encore}
484+
*/
485+
configureSplitChunks(callback) {
486+
webpackConfig.configureSplitChunks(callback);
418487

419488
return this;
420489
}
@@ -654,27 +723,6 @@ class Encore {
654723
return this;
655724
}
656725

657-
/**
658-
* Call this if you plan on loading CoffeeScript files.
659-
*
660-
* Encore.enableCoffeeScriptLoader()
661-
*
662-
* Or, configure the coffee-loader options:
663-
*
664-
* Encore.enableCoffeeScriptLoader(function(coffeeScriptOptions) {
665-
* // http://coffeescript.org/#nodejs-usage
666-
* // coffeeScriptOptions.header = true;
667-
* });
668-
*
669-
* @param {function} callback
670-
* @returns {Encore}
671-
*/
672-
enableCoffeeScriptLoader(callback = () => {}) {
673-
webpackConfig.enableCoffeeScriptLoader(callback);
674-
675-
return this;
676-
}
677-
678726
/**
679727
* Call this to enable forked type checking for TypeScript loader
680728
* https://github.com/TypeStrong/ts-loader/blob/v2.3.0/README.md#faster-builds
@@ -981,6 +1029,22 @@ class Encore {
9811029
runtimeConfig = null;
9821030
webpackConfig = null;
9831031
}
1032+
1033+
/**
1034+
* @deprecated
1035+
* @return {void}
1036+
*/
1037+
configureExtractTextPlugin() {
1038+
throw new Error('The configureExtractTextPlugin() method was removed from Encore. The underlying plugin was removed from Webpack 4.');
1039+
}
1040+
1041+
/**
1042+
* @deprecated
1043+
* @return {void}
1044+
*/
1045+
enableCoffeeScriptLoader() {
1046+
throw new Error('The enableCoffeeScriptLoader() method and CoffeeScript support was removed from Encore due to support problems with Webpack 4. If you are interested in this feature, please submit a pull request!');
1047+
}
9841048
}
9851049

9861050
// Proxy the API in order to prevent calls to most of its methods

0 commit comments

Comments
 (0)