Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for sourcemaps, esModules #46

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions configureWebpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ async function configureWebpack(env) {
// Add JSX to support imports from .jsx source w/o needing to add the extension.
// Include "*" to continue supporting other imports that *do* specify an extension
// within the import statement (i.e. `import './foo.png'`). Yes, it's confusing.
extensions: ['*', '.js', '.ts', '.jsx', '.tsx', '.json']
extensions: ['.*', '.js', '.ts', '.jsx', '.tsx', '.json']
},

// Ensure Webpack can find loaders installed both within the top-level node_modules dir for
Expand Down Expand Up @@ -422,7 +422,13 @@ async function configureWebpack(env) {
test: /\.mjs$/,
type: 'javascript/auto'
},

//------------------------
// Handle non-esModules from within esModules without specifying their file extension
//------------------------
{
test: /\.m?js$/,
resolve: {fullySpecified: false}
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading webpack docs on rules, these are nested under a oneOf block, and so I would expect that only the first matching rule would be applied. I believe this means that this rule would never get hit for .mjs files given the rule above. Do we want to add the same {fullySpecified: false} to the first rule in the list to cover mjs files?

Also, to the bigger point, I'm not sure how to interpret the comment "Handle non-esModules from within esModules without specifying their file extension" - can you help remind me what this is changing / fixing?

Our top-level resolve block has the list of extensions.

I see in the docs that this fullySpecified option is (weirdly?) called out only within the rules section - https://webpack.js.org/configuration/module/#resolvefullyspecified - but then I don't see it within the top-level docs for resolve - https://webpack.js.org/configuration/resolve/#resolve

I don't really know what to make of that, and I'm struggling to understand what the docs are saying here. Don't we get the behavior from the top-level block where any imports will match files with extensions in the list? What does this new directive do differently? What issue are we hitting with dev-utils that this overcomes?

//------------------------
// Image processing
// Encodes `url()` references directly when small enough.
Expand Down Expand Up @@ -601,6 +607,11 @@ async function configureWebpack(env) {
options: {
name: 'static/media/[name].[hash:8].[ext]'
}
},
{
test: /\.js$/,
enforce: "pre",
use: ["source-map-loader"],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will we hit this new rule, given the oneOf block it's nested underneath? I would expect any js file to be captured and processed by the second rule in the array, and would not think that anything would hit this new rule.

Did you see any effect from it?

}
]
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"sass": "~1.63.4",
"sass-loader": "~13.3.0",
"sass-material-colors": "~0.0.5",
"source-map-loader": "^4.0.1",
"style-loader": "~3.3.2",
"terser-webpack-plugin": "~5.3.7",
"url-loader": "~4.1.1",
Expand Down
23 changes: 22 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,11 @@
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==

abab@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.6.tgz#41b80f2c871d19686216b82309231cfd3cb3d291"
integrity sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==

accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.8:
version "1.3.8"
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e"
Expand Down Expand Up @@ -3329,6 +3334,13 @@ [email protected]:
dependencies:
safer-buffer ">= 2.1.2 < 3"

iconv-lite@^0.6.3:
version "0.6.3"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501"
integrity sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==
dependencies:
safer-buffer ">= 2.1.2 < 3.0.0"

icss-utils@^5.0.0, icss-utils@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-5.1.0.tgz#c6be6858abd013d768e98366ae47e25d5887b1ae"
Expand Down Expand Up @@ -4699,7 +4711,7 @@ safe-regex-test@^1.0.0:
get-intrinsic "^1.1.3"
is-regex "^1.1.4"

"safer-buffer@>= 2.1.2 < 3":
"safer-buffer@>= 2.1.2 < 3", "safer-buffer@>= 2.1.2 < 3.0.0":
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
Expand Down Expand Up @@ -4898,6 +4910,15 @@ sockjs@^0.3.24:
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==

source-map-loader@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-4.0.1.tgz#72f00d05f5d1f90f80974eda781cbd7107c125f2"
integrity sha512-oqXpzDIByKONVY8g1NUPOTQhe0UTU5bWUl32GSkqK2LjJj0HmwTMVKxcUip0RgAYhY1mqgOxjbQM48a0mmeNfA==
dependencies:
abab "^2.0.6"
iconv-lite "^0.6.3"
source-map-js "^1.0.2"

source-map-support@~0.5.20:
version "0.5.21"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
Expand Down