Skip to content

Commit

Permalink
Merge branch 'webpack:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
thomastay committed Mar 22, 2023
2 parents 2cad865 + a3f49f3 commit f33c2b0
Show file tree
Hide file tree
Showing 76 changed files with 548 additions and 107 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Expand Up @@ -27,7 +27,7 @@ jobs:
node-version: 17.x
cache: "yarn"
- run: yarn --frozen-lockfile
- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: .eslintcache
key: lint-${{ env.GITHUB_SHA }}
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
- run: yarn --frozen-lockfile
- run: yarn link --frozen-lockfile || true
- run: yarn link webpack --frozen-lockfile
- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: .jest-cache
key: jest-unit-${{ env.GITHUB_SHA }}
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
- run: yarn --frozen-lockfile
- run: yarn link --frozen-lockfile || true
- run: yarn link webpack --frozen-lockfile
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: .jest-cache
key: jest-integration-${{ env.GITHUB_SHA }}
Expand Down
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -158,11 +158,11 @@ or are automatically applied via regex from your webpack configuration.

#### Transpiling

| Name | Status | Install Size | Description |
| :--------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------: | :------------: | :------------------------------------------------------------------------------------------------ |
| <a href="https://github.com/babel/babel-loader"><img width="48" height="48" title="babel-loader" src="https://worldvectorlogo.com/logos/babel-10.svg"></a> | ![babel-npm] | ![babel-size] | Loads ES2015+ code and transpiles to ES5 using <a href="https://github.com/babel/babel">Babel</a> |
| <a href="https://github.com/TypeStrong/ts-loader"><img width="48" height="48" src="https://cdn.rawgit.com/Microsoft/TypeScript/master/doc/logo.svg"></a> | ![type-npm] | ![type-size] | Loads TypeScript like JavaScript |
| <a href="https://github.com/webpack-contrib/coffee-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a> | ![coffee-npm] | ![coffee-size] | Loads CoffeeScript like JavaScript |
| Name | Status | Install Size | Description |
| :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------: | :------------: | :------------------------------------------------------------------------------------------------ |
| <a href="https://github.com/babel/babel-loader"><img width="48" height="48" title="babel-loader" src="https://worldvectorlogo.com/logos/babel-10.svg"></a> | ![babel-npm] | ![babel-size] | Loads ES2015+ code and transpiles to ES5 using <a href="https://github.com/babel/babel">Babel</a> |
| <a href="https://github.com/TypeStrong/ts-loader"><img width="48" height="48" src="https://raw.githubusercontent.com/microsoft/TypeScript-Website/f407e1ae19e5e990d9901ac8064a32a8cc60edf0/packages/typescriptlang-org/static/branding/ts-logo-128.svg"></a> | ![type-npm] | ![type-size] | Loads TypeScript like JavaScript |
| <a href="https://github.com/webpack-contrib/coffee-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a> | ![coffee-npm] | ![coffee-size] | Loads CoffeeScript like JavaScript |

[babel-npm]: https://img.shields.io/npm/v/babel-loader.svg
[babel-size]: https://packagephobia.com/badge?p=babel-loader
Expand All @@ -175,7 +175,7 @@ or are automatically applied via regex from your webpack configuration.

| Name | Status | Install Size | Description |
| :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------: | :--------------: | :-------------------------------------------------------------------------------------- |
| <a href="https://github.com/webpack-contrib/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5.svg"></a> | ![html-npm] | ![html-size] | Exports HTML as string, requires references to static resources |
| <a href="https://github.com/webpack-contrib/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5-2.svg"></a> | ![html-npm] | ![html-size] | Exports HTML as string, requires references to static resources |
| <a href="https://github.com/pugjs/pug-loader"><img width="48" height="48" src="https://cdn.rawgit.com/pugjs/pug-logo/master/SVG/pug-final-logo-_-colour-128.svg"></a> | ![pug-npm] | ![pug-size] | Loads Pug templates and returns a function |
| <a href="https://github.com/webdiscus/pug-loader"><img width="48" height="48" src="https://cdn.rawgit.com/pugjs/pug-logo/master/SVG/pug-final-logo-_-colour-128.svg"></a> | ![pug3-npm] | ![pug3-size] | Compiles Pug to a function or HTML string, useful for use with Vue, React, Angular |
| <a href="https://github.com/peerigon/markdown-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/markdown.svg"></a> | ![md-npm] | ![md-size] | Compiles Markdown to HTML |
Expand Down
13 changes: 13 additions & 0 deletions bin/webpack.js
Expand Up @@ -53,6 +53,19 @@ const isInstalled = packageName => {
}
} while (dir !== (dir = path.dirname(dir)));

// https://github.com/nodejs/node/blob/v18.9.1/lib/internal/modules/cjs/loader.js#L1274
// eslint-disable-next-line no-warning-comments
// @ts-ignore
for (const internalPath of require("module").globalPaths) {
try {
if (fs.statSync(path.join(internalPath, packageName)).isDirectory()) {
return true;
}
} catch (_error) {
// Nothing
}
}

return false;
};

Expand Down
12 changes: 11 additions & 1 deletion declarations.d.ts
Expand Up @@ -246,10 +246,20 @@ declare module "@webassemblyjs/ast" {
declare module "webpack-sources" {
export type MapOptions = { columns?: boolean; module?: boolean };

export type RawSourceMap = {
version: number;
sources: string[];
names: string[];
sourceRoot?: string;
sourcesContent?: string[];
mappings: string;
file: string;
};

export abstract class Source {
size(): number;

map(options?: MapOptions): Object;
map(options?: MapOptions): RawSourceMap | null;

sourceAndMap(options?: MapOptions): {
source: string | Buffer;
Expand Down
6 changes: 6 additions & 0 deletions declarations/LoaderContext.d.ts
Expand Up @@ -212,6 +212,12 @@ export interface LoaderRunnerLoaderContext<OptionsType> {
* Example: "/abc/resource.js?query#frag"
*/
resource: string;

/**
* Target of compilation.
* Example: "web"
*/
target: string;
}

type AdditionalData = {
Expand Down
2 changes: 1 addition & 1 deletion examples/chunkhash/README.md
Expand Up @@ -20,7 +20,7 @@ import("./async2");
```javascript
var path = require("path");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
entry: {
main: "./example"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/chunkhash/webpack.config.js
@@ -1,6 +1,6 @@
var path = require("path");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
entry: {
main: "./example"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/coffee-script/webpack.config.js
@@ -1,5 +1,5 @@
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
module: {
rules: [
{
Expand Down
2 changes: 1 addition & 1 deletion examples/common-chunk-grandchildren/README.md
Expand Up @@ -86,7 +86,7 @@ module.exports = function() {
const path = require("path");

module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
entry: {
main: ["./example.js"]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/common-chunk-grandchildren/webpack.config.js
Expand Up @@ -2,7 +2,7 @@
const path = require("path");

module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
entry: {
main: ["./example.js"]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/dll-app-and-vendor/0-vendor/README.md
Expand Up @@ -13,7 +13,7 @@ var path = require("path");
var webpack = require("../../../");

module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
context: __dirname,
entry: ["example-vendor"],
output: {
Expand Down
2 changes: 1 addition & 1 deletion examples/dll-app-and-vendor/0-vendor/webpack.config.js
Expand Up @@ -2,7 +2,7 @@ var path = require("path");
var webpack = require("../../../");

module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
context: __dirname,
entry: ["example-vendor"],
output: {
Expand Down
2 changes: 1 addition & 1 deletion examples/dll-user/README.md
Expand Up @@ -10,7 +10,7 @@ This is the _user_ bundle, which uses the manifest from [dll-reference example](
var path = require("path");
var webpack = require("../../");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
plugins: [
new webpack.DllReferencePlugin({
context: path.join(__dirname, "..", "dll"),
Expand Down
2 changes: 1 addition & 1 deletion examples/dll-user/webpack.config.js
@@ -1,7 +1,7 @@
var path = require("path");
var webpack = require("../../");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
plugins: [
new webpack.DllReferencePlugin({
context: path.join(__dirname, "..", "dll"),
Expand Down
2 changes: 1 addition & 1 deletion examples/dll/README.md
Expand Up @@ -10,7 +10,7 @@ This is the _reference_ bundle (with the manifests) for [dll user example](https
var path = require("path");
var webpack = require("../../");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
resolve: {
extensions: [".js", ".jsx"]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/dll/webpack.config.js
@@ -1,7 +1,7 @@
var path = require("path");
var webpack = require("../../");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
resolve: {
extensions: [".js", ".jsx"]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/explicit-vendor-chunk/README.md
Expand Up @@ -6,7 +6,7 @@ var webpack = require("../../");
module.exports = [
{
name: "vendor",
// mode: "development || "production",
// mode: "development" || "production",
entry: ["./vendor", "./vendor2"],
output: {
path: path.resolve(__dirname, "dist"),
Expand All @@ -23,7 +23,7 @@ module.exports = [

{
name: "app",
// mode: "development || "production",
// mode: "development" || "production",
dependencies: ["vendor"],
entry: {
pageA: "./pageA",
Expand Down
4 changes: 2 additions & 2 deletions examples/explicit-vendor-chunk/webpack.config.js
Expand Up @@ -3,7 +3,7 @@ var webpack = require("../../");
module.exports = [
{
name: "vendor",
// mode: "development || "production",
// mode: "development" || "production",
entry: ["./vendor", "./vendor2"],
output: {
path: path.resolve(__dirname, "dist"),
Expand All @@ -20,7 +20,7 @@ module.exports = [

{
name: "app",
// mode: "development || "production",
// mode: "development" || "production",
dependencies: ["vendor"],
entry: {
pageA: "./pageA",
Expand Down
2 changes: 1 addition & 1 deletion examples/externals/README.md
Expand Up @@ -28,7 +28,7 @@ exports.exampleValue = subtract(add(42, 2), 2);

```javascript
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
output: {
libraryTarget: "umd"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/externals/webpack.config.js
@@ -1,5 +1,5 @@
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
output: {
libraryTarget: "umd"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/extra-async-chunk-advanced/README.md
Expand Up @@ -23,7 +23,7 @@ require.ensure(["./a", "./e"], function(require) {

```javascript
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
optimization: {
splitChunks: {
minSize: 0 // This example is too small
Expand Down
2 changes: 1 addition & 1 deletion examples/extra-async-chunk-advanced/webpack.config.js
@@ -1,5 +1,5 @@
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
optimization: {
splitChunks: {
minSize: 0 // This example is too small
Expand Down
2 changes: 1 addition & 1 deletion examples/extra-async-chunk/webpack.config.js
@@ -1,5 +1,5 @@
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
optimization: {
splitChunks: {
minSize: 0 // This example is too small
Expand Down
2 changes: 1 addition & 1 deletion examples/harmony-library/README.md
Expand Up @@ -3,7 +3,7 @@
```javascript
var path = require("path");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
entry: "./example",
output: {
path: path.join(__dirname, "dist"),
Expand Down
2 changes: 1 addition & 1 deletion examples/harmony-library/webpack.config.js
@@ -1,6 +1,6 @@
var path = require("path");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
entry: "./example",
output: {
path: path.join(__dirname, "dist"),
Expand Down
2 changes: 1 addition & 1 deletion examples/harmony-unused/webpack.config.js
@@ -1,5 +1,5 @@
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
optimization: {
concatenateModules: false
}
Expand Down
2 changes: 1 addition & 1 deletion examples/http2-aggressive-splitting/README.md
Expand Up @@ -20,7 +20,7 @@ The backward compatibility (non-HTTP2 client) improves with bigger `maxSize`, as
var path = require("path");
var webpack = require("../../");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
cache: true, // better performance for the AggressiveSplittingPlugin
entry: "./example",
output: {
Expand Down
2 changes: 1 addition & 1 deletion examples/http2-aggressive-splitting/webpack.config.js
@@ -1,7 +1,7 @@
var path = require("path");
var webpack = require("../../");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
cache: true, // better performance for the AggressiveSplittingPlugin
entry: "./example",
output: {
Expand Down
2 changes: 1 addition & 1 deletion examples/hybrid-routing/README.md
Expand Up @@ -3,7 +3,7 @@
```javascript
var path = require("path");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
entry: {
// The entry points for the pages
// They also contains router
Expand Down
2 changes: 1 addition & 1 deletion examples/hybrid-routing/webpack.config.js
@@ -1,6 +1,6 @@
var path = require("path");
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
entry: {
// The entry points for the pages
// They also contains router
Expand Down
2 changes: 1 addition & 1 deletion examples/loader/webpack.config.js
@@ -1,5 +1,5 @@
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
module: {
rules: [
{
Expand Down
2 changes: 1 addition & 1 deletion examples/many-pages/README.md
Expand Up @@ -26,7 +26,7 @@ Note: decreasing `maxInitial/AsyncRequest` will increase duplication further to

```
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
entry: {
pageA: "./pages/a",
pageB: "./pages/b",
Expand Down
2 changes: 1 addition & 1 deletion examples/many-pages/webpack.config.js
@@ -1,5 +1,5 @@
module.exports = {
// mode: "development || "production",
// mode: "development" || "production",
entry: {
pageA: "./pages/a",
pageB: "./pages/b",
Expand Down
4 changes: 2 additions & 2 deletions examples/multi-compiler/README.md
Expand Up @@ -15,7 +15,7 @@ var webpack = require("../../");
module.exports = [
{
name: "mobile",
// mode: "development || "production",
// mode: "development" || "production",
entry: "./example",
output: {
path: path.join(__dirname, "dist"),
Expand All @@ -30,7 +30,7 @@ module.exports = [

{
name: "desktop",
// mode: "development || "production",
// mode: "development" || "production",
entry: "./example",
output: {
path: path.join(__dirname, "dist"),
Expand Down
4 changes: 2 additions & 2 deletions examples/multi-compiler/webpack.config.js
Expand Up @@ -3,7 +3,7 @@ var webpack = require("../../");
module.exports = [
{
name: "mobile",
// mode: "development || "production",
// mode: "development" || "production",
entry: "./example",
output: {
path: path.join(__dirname, "dist"),
Expand All @@ -18,7 +18,7 @@ module.exports = [

{
name: "desktop",
// mode: "development || "production",
// mode: "development" || "production",
entry: "./example",
output: {
path: path.join(__dirname, "dist"),
Expand Down

0 comments on commit f33c2b0

Please sign in to comment.