From 022bb4e9950200f376f92bb35844add464f157d0 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 15 Jul 2022 09:38:24 +0530 Subject: [PATCH 1/2] docs(configuration): add `resolve.extensionAlias` --- src/content/configuration/resolve.mdx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/content/configuration/resolve.mdx b/src/content/configuration/resolve.mdx index 5b4bb39569ab..edfa12e625a0 100644 --- a/src/content/configuration/resolve.mdx +++ b/src/content/configuration/resolve.mdx @@ -261,6 +261,26 @@ module.exports = { }; ``` +### resolve.extensionAlias + +`object` + +An object which maps extension to extension aliases. + +**webpack.config.js** + +```js +module.exports = { + //... + resolve: { + extensionAlias: { + '.js': ['.ts', '.js'], + '.mjs': ['.mts', '.mjs'], + }, + }, +}; +``` + ### resolve.fallback `object` From 6d9759af3c75792ff9a6f2120da2b92db015ba0f Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 15 Jul 2022 16:05:25 +0530 Subject: [PATCH 2/2] chore: sort --- src/content/configuration/resolve.mdx | 38 +++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/content/configuration/resolve.mdx b/src/content/configuration/resolve.mdx index edfa12e625a0..a24d895b2025 100644 --- a/src/content/configuration/resolve.mdx +++ b/src/content/configuration/resolve.mdx @@ -227,11 +227,11 @@ module.exports = { }; ``` -### resolve.extensions +### resolve.extensionAlias -`[string] = ['.js', '.json', '.wasm']` +`object` -Attempt to resolve these extensions in order. If multiple files share the same name but have different extensions, webpack will resolve the one with the extension listed first in the array and skip the rest. +An object which maps extension to extension aliases. **webpack.config.js** @@ -239,44 +239,44 @@ Attempt to resolve these extensions in order. If multiple files share the same n module.exports = { //... resolve: { - extensions: ['.js', '.json', '.wasm'], + extensionAlias: { + '.js': ['.ts', '.js'], + '.mjs': ['.mts', '.mjs'], + }, }, }; ``` -which is what enables users to leave off the extension when importing: +### resolve.extensions -```js -import File from '../path/to/file'; -``` +`[string] = ['.js', '.json', '.wasm']` -Note that using `resolve.extensions` like above will **override the default array**, meaning that webpack will no longer try to resolve modules using the default extensions. However you can use `'...'` to access the default extensions: +Attempt to resolve these extensions in order. If multiple files share the same name but have different extensions, webpack will resolve the one with the extension listed first in the array and skip the rest. + +**webpack.config.js** ```js module.exports = { //... resolve: { - extensions: ['.ts', '...'], + extensions: ['.js', '.json', '.wasm'], }, }; ``` -### resolve.extensionAlias - -`object` +which is what enables users to leave off the extension when importing: -An object which maps extension to extension aliases. +```js +import File from '../path/to/file'; +``` -**webpack.config.js** +Note that using `resolve.extensions` like above will **override the default array**, meaning that webpack will no longer try to resolve modules using the default extensions. However you can use `'...'` to access the default extensions: ```js module.exports = { //... resolve: { - extensionAlias: { - '.js': ['.ts', '.js'], - '.mjs': ['.mts', '.mjs'], - }, + extensions: ['.ts', '...'], }, }; ```