-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not import non javascript chunks
- Loading branch information
Showing
9 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.bar { | ||
color: #fff; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { countBy } from "lodash-es"; | ||
|
||
import "./bar.css"; | ||
|
||
const result = countBy([6.1, 4.2, 6.3], Math.floor); | ||
|
||
export default result["6"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.foo { | ||
color: #fff; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { dropRight } from "lodash-es"; | ||
|
||
import "./foo.css"; | ||
|
||
const result = dropRight([10, 20, 30], 2); | ||
|
||
export default result[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import foo from "./foo.js"; | ||
import bar from "./bar.js"; | ||
|
||
console.log(foo + bar); | ||
|
||
it("should not contain non javascript chunk in the main bundle", () => { | ||
const fs = require("fs"); | ||
const source = fs.readFileSync(__STATS__.outputPath + "/main.mjs", "utf-8"); | ||
|
||
expect(__STATS__.chunks.some(c => c.names.includes("style"))).toBe(true); | ||
// Should not import "./style.mjs";` | ||
expect(source).not.toMatch( | ||
/import\s\*\sas+\s__webpack_chunk_[0-9]+__\sfrom\s"\.\/style\.mjs"/g | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
findBundle: function (i, options) { | ||
return ["main.mjs", "vendor.mjs", "runtime.mjs"]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const supportsRequireInModule = require("../../../helpers/supportsRequireInModule"); | ||
|
||
module.exports = () => { | ||
return supportsRequireInModule(); | ||
}; |
77 changes: 77 additions & 0 deletions
77
test/configCases/output-module/issue-16040/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | ||
|
||
module.exports = { | ||
mode: "production", | ||
devtool: false, | ||
experiments: { | ||
outputModule: true | ||
}, | ||
output: { | ||
publicPath: "/", | ||
filename: "[name].mjs", | ||
chunkFilename: "[name].chunk.js", | ||
assetModuleFilename: "[hash][ext][query]", | ||
module: true, | ||
libraryTarget: "module", | ||
chunkFormat: "module", | ||
chunkLoading: "import", | ||
environment: { | ||
dynamicImport: true, | ||
module: true | ||
} | ||
}, | ||
|
||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/i, | ||
use: [MiniCssExtractPlugin.loader, "css-loader"] | ||
} | ||
] | ||
}, | ||
|
||
plugins: [ | ||
new MiniCssExtractPlugin({ | ||
filename: "style.css", | ||
chunkFilename: "[id].css" | ||
}) | ||
], | ||
|
||
optimization: { | ||
splitChunks: { | ||
chunks: "all", | ||
|
||
cacheGroups: { | ||
style: { | ||
name: "style", | ||
type: "css/mini-extract", | ||
chunks: "all", | ||
enforce: true | ||
}, | ||
|
||
defaultVendors: { | ||
name: "vendor", | ||
test: /[\\/]node_modules[\\/]/, | ||
priority: -10, | ||
chunks: "initial", | ||
reuseExistingChunk: true | ||
}, | ||
|
||
default: { | ||
minChunks: 2, | ||
priority: -20, | ||
reuseExistingChunk: true | ||
} | ||
} | ||
}, | ||
|
||
runtimeChunk: { | ||
name: "runtime" | ||
}, | ||
|
||
// currently Webpack has bugs when setting concatenateModules to true while produce ES Module output. | ||
// concatenateModules: false, | ||
|
||
minimize: false | ||
} | ||
}; |