Skip to content

Commit f8b84f9

Browse files
committed
Update Webpack to 5.0.0-beta
1 parent 134f47a commit f8b84f9

26 files changed

+973
-1629
lines changed

fixtures/js/shared_example.js

-1
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

+28-54
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
*
@@ -1598,38 +1604,6 @@ class Encore {
15981604
runtimeConfig = null;
15991605
webpackConfig = null;
16001606
}
1601-
1602-
/**
1603-
* @deprecated
1604-
* @return {void}
1605-
*/
1606-
configureExtractTextPlugin() {
1607-
throw new Error('The configureExtractTextPlugin() method was removed from Encore. The underlying plugin was removed from Webpack 4.');
1608-
}
1609-
1610-
/**
1611-
* @deprecated
1612-
* @return {void}
1613-
*/
1614-
enableCoffeeScriptLoader() {
1615-
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!');
1616-
}
1617-
1618-
/**
1619-
* @deprecated
1620-
* @return {void}
1621-
*/
1622-
configureUglifyJsPlugin() {
1623-
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.');
1624-
}
1625-
1626-
/**
1627-
* @deprecated
1628-
* @return {void}
1629-
*/
1630-
configureLoaderOptionsPlugin() {
1631-
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().');
1632-
}
16331607
}
16341608

16351609
/**

lib/WebpackConfig.js

+24-49
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 = {};
@@ -157,6 +155,8 @@ class WebpackConfig {
157155
this.eslintLoaderOptionsCallback = () => {};
158156
this.tsConfigurationCallback = () => {};
159157
this.handlebarsConfigurationCallback = () => {};
158+
this.miniCssExtractLoaderConfigurationCallback = () => {};
159+
this.miniCssExtractPluginConfigurationCallback = () => {};
160160
this.loaderConfigurationCallbacks = {
161161
javascript: () => {},
162162
css: () => {},
@@ -408,18 +408,12 @@ class WebpackConfig {
408408
const allowedOptionsWithExternalConfig = ['includeNodeModules', 'exclude'];
409409

410410
for (const optionKey of Object.keys(options)) {
411-
let normalizedOptionKey = optionKey;
412-
if (optionKey === 'include_node_modules') {
413-
logger.deprecation('configureBabel: "include_node_modules" is deprecated. Please use "includeNodeModules" instead.');
414-
normalizedOptionKey = 'includeNodeModules';
415-
}
416-
417-
if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(normalizedOptionKey)) {
418-
logger.warning(`The "${normalizedOptionKey}" option of configureBabel() will not be used because your app already provides an external Babel configuration (a ".babelrc" file, ".babelrc.js" file or "babel" key in "package.json").`);
411+
if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(optionKey)) {
412+
logger.warning(`The "${optionKey}" option of configureBabel() will not be used because your app already provides an external Babel configuration (a ".babelrc" file, ".babelrc.js" file or "babel" key in "package.json").`);
419413
continue;
420414
}
421415

422-
if (normalizedOptionKey === 'includeNodeModules') {
416+
if (optionKey === 'includeNodeModules') {
423417
if (Object.keys(options).includes('exclude')) {
424418
throw new Error('"includeNodeModules" and "exclude" options can\'t be used together when calling configureBabel().');
425419
}
@@ -448,10 +442,10 @@ class WebpackConfig {
448442
// Exclude other modules
449443
return true;
450444
};
451-
} else if (!(normalizedOptionKey in this.babelOptions)) {
452-
throw new Error(`Invalid option "${normalizedOptionKey}" passed to configureBabel(). Valid keys are ${[...Object.keys(this.babelOptions), 'includeNodeModules'].join(', ')}`);
445+
} else if (!(optionKey in this.babelOptions)) {
446+
throw new Error(`Invalid option "${optionKey}" passed to configureBabel(). Valid keys are ${[...Object.keys(this.babelOptions), 'includeNodeModules'].join(', ')}`);
453447
} else {
454-
this.babelOptions[normalizedOptionKey] = options[optionKey];
448+
this.babelOptions[optionKey] = options[optionKey];
455449
}
456450
}
457451
}
@@ -484,6 +478,19 @@ class WebpackConfig {
484478
this.styleLoaderConfigurationCallback = callback;
485479
}
486480

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

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

@@ -524,28 +527,6 @@ class WebpackConfig {
524527
this.devServerOptionsConfigurationCallback = callback;
525528
}
526529

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

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

657-
this.sassOptions[normalizedOptionKey] = options[optionKey];
632+
this.sassOptions[optionKey] = options[optionKey];
658633
}
659634
}
660635

0 commit comments

Comments
 (0)