Skip to content

Commit eabc6fe

Browse files
committed
Update Webpack to 5.0.0-beta
1 parent b722a0e commit eabc6fe

27 files changed

+877
-1573
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
@@ -1012,6 +990,34 @@ class Encore {
1012990
return this;
1013991
}
1014992

993+
/**
994+
* Configure the mini-css-extract-plugin.
995+
*
996+
* https://github.com/webpack-contrib/mini-css-extract-plugin#configuration
997+
*
998+
* ```
999+
* Encore.configureMiniCssExtractPlugin(
1000+
* function(loaderConfig) {
1001+
* // change the loader's config
1002+
* // loaderConfig.reloadAll = true;
1003+
* },
1004+
* function(pluginConfig) {
1005+
* // change the plugin's config
1006+
* // pluginConfig.chunkFilename = '[id].css';
1007+
* }
1008+
* );
1009+
* ```
1010+
*
1011+
* @param {function} loaderOptionsCallback
1012+
* @param {function} pluginOptionsCallback
1013+
* @returns {Encore}
1014+
*/
1015+
configureMiniCssExtractPlugin(loaderOptionsCallback, pluginOptionsCallback = () => {}) {
1016+
webpackConfig.configureMiniCssExtractPlugin(loaderOptionsCallback, pluginOptionsCallback);
1017+
1018+
return this;
1019+
}
1020+
10151021
/**
10161022
* If enabled, the react preset is added to Babel.
10171023
*
@@ -1602,38 +1608,6 @@ class Encore {
16021608
runtimeConfig = null;
16031609
webpackConfig = null;
16041610
}
1605-
1606-
/**
1607-
* @deprecated
1608-
* @return {void}
1609-
*/
1610-
configureExtractTextPlugin() {
1611-
throw new Error('The configureExtractTextPlugin() method was removed from Encore. The underlying plugin was removed from Webpack 4.');
1612-
}
1613-
1614-
/**
1615-
* @deprecated
1616-
* @return {void}
1617-
*/
1618-
enableCoffeeScriptLoader() {
1619-
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!');
1620-
}
1621-
1622-
/**
1623-
* @deprecated
1624-
* @return {void}
1625-
*/
1626-
configureUglifyJsPlugin() {
1627-
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.');
1628-
}
1629-
1630-
/**
1631-
* @deprecated
1632-
* @return {void}
1633-
*/
1634-
configureLoaderOptionsPlugin() {
1635-
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().');
1636-
}
16371611
}
16381612

16391613
/**

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 = {};
@@ -158,6 +156,8 @@ class WebpackConfig {
158156
this.eslintLoaderOptionsCallback = () => {};
159157
this.tsConfigurationCallback = () => {};
160158
this.handlebarsConfigurationCallback = () => {};
159+
this.miniCssExtractLoaderConfigurationCallback = () => {};
160+
this.miniCssExtractPluginConfigurationCallback = () => {};
161161
this.loaderConfigurationCallbacks = {
162162
javascript: () => {},
163163
css: () => {},
@@ -409,18 +409,12 @@ class WebpackConfig {
409409
const allowedOptionsWithExternalConfig = ['includeNodeModules', 'exclude'];
410410

411411
for (const optionKey of Object.keys(options)) {
412-
let normalizedOptionKey = optionKey;
413-
if (optionKey === 'include_node_modules') {
414-
logger.deprecation('configureBabel: "include_node_modules" is deprecated. Please use "includeNodeModules" instead.');
415-
normalizedOptionKey = 'includeNodeModules';
416-
}
417-
418-
if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(normalizedOptionKey)) {
419-
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 "babelrc.config.js" file or "babel" key in "package.json").`);
412+
if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(optionKey)) {
413+
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").`);
420414
continue;
421415
}
422416

423-
if (normalizedOptionKey === 'includeNodeModules') {
417+
if (optionKey === 'includeNodeModules') {
424418
if (Object.keys(options).includes('exclude')) {
425419
throw new Error('"includeNodeModules" and "exclude" options can\'t be used together when calling configureBabel().');
426420
}
@@ -449,10 +443,10 @@ class WebpackConfig {
449443
// Exclude other modules
450444
return true;
451445
};
452-
} else if (!(normalizedOptionKey in this.babelOptions)) {
453-
throw new Error(`Invalid option "${normalizedOptionKey}" passed to configureBabel(). Valid keys are ${[...Object.keys(this.babelOptions), 'includeNodeModules'].join(', ')}`);
446+
} else if (!(optionKey in this.babelOptions)) {
447+
throw new Error(`Invalid option "${optionKey}" passed to configureBabel(). Valid keys are ${[...Object.keys(this.babelOptions), 'includeNodeModules'].join(', ')}`);
454448
} else {
455-
this.babelOptions[normalizedOptionKey] = options[optionKey];
449+
this.babelOptions[optionKey] = options[optionKey];
456450
}
457451
}
458452
}
@@ -485,6 +479,19 @@ class WebpackConfig {
485479
this.styleLoaderConfigurationCallback = callback;
486480
}
487481

482+
configureMiniCssExtractPlugin(loaderOptionsCallback, pluginOptionsCallback = () => {}) {
483+
if (typeof loaderOptionsCallback !== 'function') {
484+
throw new Error('Argument 1 to configureMiniCssExtractPluginLoader() must be a callback function.');
485+
}
486+
487+
if (typeof pluginOptionsCallback !== 'function') {
488+
throw new Error('Argument 2 to configureMiniCssExtractPluginLoader() must be a callback function.');
489+
}
490+
491+
this.miniCssExtractLoaderConfigurationCallback = loaderOptionsCallback;
492+
this.miniCssExtractPluginConfigurationCallback = pluginOptionsCallback;
493+
}
494+
488495
enableSingleRuntimeChunk() {
489496
this.shouldUseSingleRuntimeChunk = true;
490497
}
@@ -494,10 +501,6 @@ class WebpackConfig {
494501
}
495502

496503
splitEntryChunks() {
497-
if (this.sharedCommonsEntryName) {
498-
throw new Error('Using splitEntryChunks() and createSharedEntry() together is not supported. Use one of these strategies only to optimize your build.');
499-
}
500-
501504
this.shouldSplitEntryChunks = true;
502505
}
503506

@@ -525,28 +528,6 @@ class WebpackConfig {
525528
this.devServerOptionsConfigurationCallback = callback;
526529
}
527530

528-
createSharedEntry(name, file) {
529-
logger.deprecation('Encore.createSharedEntry() is deprecated and will be removed in a future version, please use Encore.splitEntryChunks() or Encore.addCacheGroup() instead.');
530-
531-
if (this.shouldSplitEntryChunks) {
532-
throw new Error('Using splitEntryChunks() and createSharedEntry() together is not supported. Use one of these strategies only to optimize your build.');
533-
}
534-
535-
// don't allow to call this twice
536-
if (this.sharedCommonsEntryName) {
537-
throw new Error('createSharedEntry() cannot be called multiple times: you can only create *one* shared entry.');
538-
}
539-
540-
if (Array.isArray(file)) {
541-
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.');
542-
}
543-
544-
this.sharedCommonsEntryName = name;
545-
this.sharedCommonsEntryFile = file;
546-
547-
this.addEntry(name, file);
548-
}
549-
550531
addCacheGroup(name, options) {
551532
if (typeof name !== 'string') {
552533
throw new Error('Argument 1 to addCacheGroup() must be a string.');
@@ -645,17 +626,11 @@ class WebpackConfig {
645626
this.sassLoaderOptionsCallback = sassLoaderOptionsCallback;
646627

647628
for (const optionKey of Object.keys(options)) {
648-
let normalizedOptionKey = optionKey;
649-
if (optionKey === 'resolve_url_loader') {
650-
logger.deprecation('enableSassLoader: "resolve_url_loader" is deprecated. Please use "resolveUrlLoader" instead.');
651-
normalizedOptionKey = 'resolveUrlLoader';
652-
}
653-
654-
if (!(normalizedOptionKey in this.sassOptions)) {
655-
throw new Error(`Invalid option "${normalizedOptionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`);
629+
if (!(optionKey in this.sassOptions)) {
630+
throw new Error(`Invalid option "${optionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`);
656631
}
657632

658-
this.sassOptions[normalizedOptionKey] = options[optionKey];
633+
this.sassOptions[optionKey] = options[optionKey];
659634
}
660635
}
661636

0 commit comments

Comments
 (0)