Skip to content

Commit beb34ac

Browse files
committed
Update Webpack to 5.0.0-beta
1 parent e773dda commit beb34ac

31 files changed

+1215
-1919
lines changed

.appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cache:
33
- "%LOCALAPPDATA%\\Yarn"
44

55
environment:
6-
nodejs_version: "8"
6+
nodejs_version: "10"
77

88
platform:
99
- x86

.travis.yml

-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,5 @@ matrix:
3636
- os: linux
3737
node_js: "10"
3838
env: JOB_PART=test
39-
- os: linux
40-
node_js: "8"
41-
env: JOB_PART=test
4239

4340
script: npm run $JOB_PART

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
*
@@ -1562,38 +1568,6 @@ class Encore {
15621568
runtimeConfig = null;
15631569
webpackConfig = null;
15641570
}
1565-
1566-
/**
1567-
* @deprecated
1568-
* @return {void}
1569-
*/
1570-
configureExtractTextPlugin() {
1571-
throw new Error('The configureExtractTextPlugin() method was removed from Encore. The underlying plugin was removed from Webpack 4.');
1572-
}
1573-
1574-
/**
1575-
* @deprecated
1576-
* @return {void}
1577-
*/
1578-
enableCoffeeScriptLoader() {
1579-
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!');
1580-
}
1581-
1582-
/**
1583-
* @deprecated
1584-
* @return {void}
1585-
*/
1586-
configureUglifyJsPlugin() {
1587-
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.');
1588-
}
1589-
1590-
/**
1591-
* @deprecated
1592-
* @return {void}
1593-
*/
1594-
configureLoaderOptionsPlugin() {
1595-
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().');
1596-
}
15971571
}
15981572

15991573
/**

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 = {};
@@ -153,6 +151,8 @@ class WebpackConfig {
153151
this.eslintLoaderOptionsCallback = () => {};
154152
this.tsConfigurationCallback = () => {};
155153
this.handlebarsConfigurationCallback = () => {};
154+
this.miniCssExtractLoaderConfigurationCallback = () => {};
155+
this.miniCssExtractPluginConfigurationCallback = () => {};
156156
this.loaderConfigurationCallbacks = {
157157
javascript: () => {},
158158
css: () => {},
@@ -404,18 +404,12 @@ class WebpackConfig {
404404
const allowedOptionsWithExternalConfig = ['includeNodeModules', 'exclude'];
405405

406406
for (const optionKey of Object.keys(options)) {
407-
let normalizedOptionKey = optionKey;
408-
if (optionKey === 'include_node_modules') {
409-
logger.deprecation('configureBabel: "include_node_modules" is deprecated. Please use "includeNodeModules" instead.');
410-
normalizedOptionKey = 'includeNodeModules';
411-
}
412-
413-
if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(normalizedOptionKey)) {
414-
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").`);
407+
if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(optionKey)) {
408+
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").`);
415409
continue;
416410
}
417411

418-
if (normalizedOptionKey === 'includeNodeModules') {
412+
if (optionKey === 'includeNodeModules') {
419413
if (Object.keys(options).includes('exclude')) {
420414
throw new Error('"includeNodeModules" and "exclude" options can\'t be used together when calling configureBabel().');
421415
}
@@ -444,10 +438,10 @@ class WebpackConfig {
444438
// Exclude other modules
445439
return true;
446440
};
447-
} else if (!(normalizedOptionKey in this.babelOptions)) {
448-
throw new Error(`Invalid option "${normalizedOptionKey}" passed to configureBabel(). Valid keys are ${[...Object.keys(this.babelOptions), 'includeNodeModules'].join(', ')}`);
441+
} else if (!(optionKey in this.babelOptions)) {
442+
throw new Error(`Invalid option "${optionKey}" passed to configureBabel(). Valid keys are ${[...Object.keys(this.babelOptions), 'includeNodeModules'].join(', ')}`);
449443
} else {
450-
this.babelOptions[normalizedOptionKey] = options[optionKey];
444+
this.babelOptions[optionKey] = options[optionKey];
451445
}
452446
}
453447
}
@@ -472,6 +466,19 @@ class WebpackConfig {
472466
this.cssLoaderConfigurationCallback = callback;
473467
}
474468

469+
configureMiniCssExtractPlugin(loaderOptionsCallback, pluginOptionsCallback = () => {}) {
470+
if (typeof loaderOptionsCallback !== 'function') {
471+
throw new Error('Argument 1 to configureMiniCssExtractPluginLoader() must be a callback function.');
472+
}
473+
474+
if (typeof pluginOptionsCallback !== 'function') {
475+
throw new Error('Argument 2 to configureMiniCssExtractPluginLoader() must be a callback function.');
476+
}
477+
478+
this.miniCssExtractLoaderConfigurationCallback = loaderOptionsCallback;
479+
this.miniCssExtractPluginConfigurationCallback = pluginOptionsCallback;
480+
}
481+
475482
enableSingleRuntimeChunk() {
476483
this.shouldUseSingleRuntimeChunk = true;
477484
}
@@ -481,10 +488,6 @@ class WebpackConfig {
481488
}
482489

483490
splitEntryChunks() {
484-
if (this.sharedCommonsEntryName) {
485-
throw new Error('Using splitEntryChunks() and createSharedEntry() together is not supported. Use one of these strategies only to optimize your build.');
486-
}
487-
488491
this.shouldSplitEntryChunks = true;
489492
}
490493

@@ -512,28 +515,6 @@ class WebpackConfig {
512515
this.devServerOptionsConfigurationCallback = callback;
513516
}
514517

515-
createSharedEntry(name, file) {
516-
logger.deprecation('Encore.createSharedEntry() is deprecated and will be removed in a future version, please use Encore.splitEntryChunks() or Encore.addCacheGroup() instead.');
517-
518-
if (this.shouldSplitEntryChunks) {
519-
throw new Error('Using splitEntryChunks() and createSharedEntry() together is not supported. Use one of these strategies only to optimize your build.');
520-
}
521-
522-
// don't allow to call this twice
523-
if (this.sharedCommonsEntryName) {
524-
throw new Error('createSharedEntry() cannot be called multiple times: you can only create *one* shared entry.');
525-
}
526-
527-
if (Array.isArray(file)) {
528-
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.');
529-
}
530-
531-
this.sharedCommonsEntryName = name;
532-
this.sharedCommonsEntryFile = file;
533-
534-
this.addEntry(name, file);
535-
}
536-
537518
addCacheGroup(name, options) {
538519
if (typeof name !== 'string') {
539520
throw new Error('Argument 1 to addCacheGroup() must be a string.');
@@ -632,17 +613,11 @@ class WebpackConfig {
632613
this.sassLoaderOptionsCallback = sassLoaderOptionsCallback;
633614

634615
for (const optionKey of Object.keys(options)) {
635-
let normalizedOptionKey = optionKey;
636-
if (optionKey === 'resolve_url_loader') {
637-
logger.deprecation('enableSassLoader: "resolve_url_loader" is deprecated. Please use "resolveUrlLoader" instead.');
638-
normalizedOptionKey = 'resolveUrlLoader';
639-
}
640-
641-
if (!(normalizedOptionKey in this.sassOptions)) {
642-
throw new Error(`Invalid option "${normalizedOptionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`);
616+
if (!(optionKey in this.sassOptions)) {
617+
throw new Error(`Invalid option "${optionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`);
643618
}
644619

645-
this.sassOptions[normalizedOptionKey] = options[optionKey];
620+
this.sassOptions[optionKey] = options[optionKey];
646621
}
647622
}
648623

0 commit comments

Comments
 (0)