Skip to content

Commit f3843ca

Browse files
committed
Update Webpack to 5.0.0
1 parent d772785 commit f3843ca

28 files changed

+2555
-1849
lines changed

fixtures/js/shared_example.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// used in a createdSharedEntry() test
21
require('./no_require');
32
require('./requires_arrow_function');
43
require('./../css/h1_style.css');

index.js

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -454,28 +454,6 @@ class Encore {
454454
return this;
455455
}
456456

457-
/**
458-
* Add a "commons" file that holds JS shared by multiple chunks/files.
459-
*
460-
* For example:
461-
*
462-
* ```
463-
* Encore.createSharedEntry(
464-
* 'vendor',
465-
* './src/shared.js'
466-
* );
467-
* ```
468-
*
469-
* @param {string} name The chunk name (e.g. vendor to create a vendor.js)
470-
* @param {string} file A file whose code & imports should be put into the shared file.
471-
* @returns {Encore}
472-
*/
473-
createSharedEntry(name, file) {
474-
webpackConfig.createSharedEntry(name, file);
475-
476-
return this;
477-
}
478-
479457
/**
480458
* Add a new cache group to Webpack's SplitChunksPlugin.
481459
* This can, for instance, be used to extract code that
@@ -1030,6 +1008,34 @@ class Encore {
10301008
return this;
10311009
}
10321010

1011+
/**
1012+
* Configure the mini-css-extract-plugin.
1013+
*
1014+
* https://github.com/webpack-contrib/mini-css-extract-plugin#configuration
1015+
*
1016+
* ```
1017+
* Encore.configureMiniCssExtractPlugin(
1018+
* function(loaderConfig) {
1019+
* // change the loader's config
1020+
* // loaderConfig.reloadAll = true;
1021+
* },
1022+
* function(pluginConfig) {
1023+
* // change the plugin's config
1024+
* // pluginConfig.chunkFilename = '[id].css';
1025+
* }
1026+
* );
1027+
* ```
1028+
*
1029+
* @param {function} loaderOptionsCallback
1030+
* @param {function} pluginOptionsCallback
1031+
* @returns {Encore}
1032+
*/
1033+
configureMiniCssExtractPlugin(loaderOptionsCallback, pluginOptionsCallback = () => {}) {
1034+
webpackConfig.configureMiniCssExtractPlugin(loaderOptionsCallback, pluginOptionsCallback);
1035+
1036+
return this;
1037+
}
1038+
10331039
/**
10341040
* If enabled, the react preset is added to Babel.
10351041
*
@@ -1634,38 +1640,6 @@ class Encore {
16341640
runtimeConfig = null;
16351641
webpackConfig = null;
16361642
}
1637-
1638-
/**
1639-
* @deprecated
1640-
* @return {void}
1641-
*/
1642-
configureExtractTextPlugin() {
1643-
throw new Error('The configureExtractTextPlugin() method was removed from Encore. The underlying plugin was removed from Webpack 4.');
1644-
}
1645-
1646-
/**
1647-
* @deprecated
1648-
* @return {void}
1649-
*/
1650-
enableCoffeeScriptLoader() {
1651-
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!');
1652-
}
1653-
1654-
/**
1655-
* @deprecated
1656-
* @return {void}
1657-
*/
1658-
configureUglifyJsPlugin() {
1659-
throw new Error('The configureUglifyJsPlugin() method was removed from Encore due to uglify-js dropping ES6+ support in its latest version. Please use configureTerserPlugin() instead.');
1660-
}
1661-
1662-
/**
1663-
* @deprecated
1664-
* @return {void}
1665-
*/
1666-
configureLoaderOptionsPlugin() {
1667-
throw new Error('The configureLoaderOptionsPlugin() method was removed from Encore. The underlying plugin should not be needed anymore unless you are using outdated loaders. If that\'s the case you can still add it using addPlugin().');
1668-
}
16691643
}
16701644

16711645
/**

lib/WebpackConfig.js

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ class WebpackConfig {
8383
this.outputPath = null;
8484
this.publicPath = null;
8585
this.manifestKeyPrefix = null;
86-
this.sharedCommonsEntryName = null;
87-
this.sharedCommonsEntryFile = null;
8886
this.cacheGroups = {};
8987
this.providedVariables = {};
9088
this.configuredFilenames = {};
@@ -163,6 +161,8 @@ class WebpackConfig {
163161
this.eslintLoaderOptionsCallback = () => {};
164162
this.tsConfigurationCallback = () => {};
165163
this.handlebarsConfigurationCallback = () => {};
164+
this.miniCssExtractLoaderConfigurationCallback = () => {};
165+
this.miniCssExtractPluginConfigurationCallback = () => {};
166166
this.loaderConfigurationCallbacks = {
167167
javascript: () => {},
168168
css: () => {},
@@ -414,18 +414,12 @@ class WebpackConfig {
414414
const allowedOptionsWithExternalConfig = ['includeNodeModules', 'exclude'];
415415

416416
for (const optionKey of Object.keys(options)) {
417-
let normalizedOptionKey = optionKey;
418-
if (optionKey === 'include_node_modules') {
419-
logger.deprecation('configureBabel: "include_node_modules" is deprecated. Please use "includeNodeModules" instead.');
420-
normalizedOptionKey = 'includeNodeModules';
421-
}
422-
423-
if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(normalizedOptionKey)) {
424-
logger.warning(`The "${normalizedOptionKey}" option of configureBabel() will not be used because your app already provides an external Babel configuration (e.g. a ".babelrc" or "babel.config.js" file or "babel" key in "package.json").`);
417+
if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(optionKey)) {
418+
logger.warning(`The "${optionKey}" option of configureBabel() will not be used because your app already provides an external Babel configuration (e.g. a ".babelrc" or "babelrc.config.js" file or "babel" key in "package.json").`);
425419
continue;
426420
}
427421

428-
if (normalizedOptionKey === 'includeNodeModules') {
422+
if (optionKey === 'includeNodeModules') {
429423
if (Object.keys(options).includes('exclude')) {
430424
throw new Error('"includeNodeModules" and "exclude" options can\'t be used together when calling configureBabel().');
431425
}
@@ -454,10 +448,10 @@ class WebpackConfig {
454448
// Exclude other modules
455449
return true;
456450
};
457-
} else if (!(normalizedOptionKey in this.babelOptions)) {
458-
throw new Error(`Invalid option "${normalizedOptionKey}" passed to configureBabel(). Valid keys are ${[...Object.keys(this.babelOptions), 'includeNodeModules'].join(', ')}`);
451+
} else if (!(optionKey in this.babelOptions)) {
452+
throw new Error(`Invalid option "${optionKey}" passed to configureBabel(). Valid keys are ${[...Object.keys(this.babelOptions), 'includeNodeModules'].join(', ')}`);
459453
} else {
460-
this.babelOptions[normalizedOptionKey] = options[optionKey];
454+
this.babelOptions[optionKey] = options[optionKey];
461455
}
462456
}
463457
}
@@ -490,6 +484,19 @@ class WebpackConfig {
490484
this.styleLoaderConfigurationCallback = callback;
491485
}
492486

487+
configureMiniCssExtractPlugin(loaderOptionsCallback, pluginOptionsCallback = () => {}) {
488+
if (typeof loaderOptionsCallback !== 'function') {
489+
throw new Error('Argument 1 to configureMiniCssExtractPluginLoader() must be a callback function.');
490+
}
491+
492+
if (typeof pluginOptionsCallback !== 'function') {
493+
throw new Error('Argument 2 to configureMiniCssExtractPluginLoader() must be a callback function.');
494+
}
495+
496+
this.miniCssExtractLoaderConfigurationCallback = loaderOptionsCallback;
497+
this.miniCssExtractPluginConfigurationCallback = pluginOptionsCallback;
498+
}
499+
493500
enableSingleRuntimeChunk() {
494501
this.shouldUseSingleRuntimeChunk = true;
495502
}
@@ -499,10 +506,6 @@ class WebpackConfig {
499506
}
500507

501508
splitEntryChunks() {
502-
if (this.sharedCommonsEntryName) {
503-
throw new Error('Using splitEntryChunks() and createSharedEntry() together is not supported. Use one of these strategies only to optimize your build.');
504-
}
505-
506509
this.shouldSplitEntryChunks = true;
507510
}
508511

@@ -530,28 +533,6 @@ class WebpackConfig {
530533
this.devServerOptionsConfigurationCallback = callback;
531534
}
532535

533-
createSharedEntry(name, file) {
534-
logger.deprecation('Encore.createSharedEntry() is deprecated and will be removed in a future version, please use Encore.splitEntryChunks() or Encore.addCacheGroup() instead.');
535-
536-
if (this.shouldSplitEntryChunks) {
537-
throw new Error('Using splitEntryChunks() and createSharedEntry() together is not supported. Use one of these strategies only to optimize your build.');
538-
}
539-
540-
// don't allow to call this twice
541-
if (this.sharedCommonsEntryName) {
542-
throw new Error('createSharedEntry() cannot be called multiple times: you can only create *one* shared entry.');
543-
}
544-
545-
if (Array.isArray(file)) {
546-
throw new Error('Argument 2 to createSharedEntry() must be a single string file: not an array of files. Try creating one file that requires/imports all the modules that should be included.');
547-
}
548-
549-
this.sharedCommonsEntryName = name;
550-
this.sharedCommonsEntryFile = file;
551-
552-
this.addEntry(name, file);
553-
}
554-
555536
addCacheGroup(name, options) {
556537
if (typeof name !== 'string') {
557538
throw new Error('Argument 1 to addCacheGroup() must be a string.');
@@ -650,17 +631,11 @@ class WebpackConfig {
650631
this.sassLoaderOptionsCallback = sassLoaderOptionsCallback;
651632

652633
for (const optionKey of Object.keys(options)) {
653-
let normalizedOptionKey = optionKey;
654-
if (optionKey === 'resolve_url_loader') {
655-
logger.deprecation('enableSassLoader: "resolve_url_loader" is deprecated. Please use "resolveUrlLoader" instead.');
656-
normalizedOptionKey = 'resolveUrlLoader';
657-
}
658-
659-
if (!(normalizedOptionKey in this.sassOptions)) {
660-
throw new Error(`Invalid option "${normalizedOptionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`);
634+
if (!(optionKey in this.sassOptions)) {
635+
throw new Error(`Invalid option "${optionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`);
661636
}
662637

663-
this.sassOptions[normalizedOptionKey] = options[optionKey];
638+
this.sassOptions[optionKey] = options[optionKey];
664639
}
665640
}
666641

0 commit comments

Comments
 (0)