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

fix: crash with contenthash #869

Merged
merged 2 commits into from
Nov 4, 2021
Merged
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
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,7 @@ class MiniCssExtractPlugin {
return referencedChunk.canBeInitial()
? this.options.filename
: this.options.chunkFilename;
},
true
}
)
);

Expand Down
2 changes: 1 addition & 1 deletion test/TestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("TestCases", () => {
Object.assign(
config,
{
mode: "none",
mode: config.mode || "none",
context: directoryForCase,
},
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,16 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/get mini-css chunk filename */
/******/ (() => {
/******/ // This function allow to reference all chunks
/******/ // This function allow to reference async chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames not based on template
/******/ if (chunkId === 1) return "" + __webpack_require__.h() + ".css";
/******/ // return url for filenames based on template
/******/ return "" + chunkId + "." + __webpack_require__.h() + ".css";
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("b39c6cd65ee4f78b425e")
/******/ __webpack_require__.h = () => ("28af1b92f2511f8f1836")
/******/ })();
/******/
/******/ /* webpack/runtime/global */
Expand Down
6 changes: 2 additions & 4 deletions test/cases/chunkFilename-fullhash/expected/webpack-5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,16 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/get mini-css chunk filename */
/******/ (() => {
/******/ // This function allow to reference all chunks
/******/ // This function allow to reference async chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames not based on template
/******/ if (chunkId === 1) return "" + __webpack_require__.h() + ".css";
/******/ // return url for filenames based on template
/******/ return "" + chunkId + "." + __webpack_require__.h() + ".css";
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("4119f46f7fa72336b928")
/******/ __webpack_require__.h = () => ("845a2495b51038b0d047")
/******/ })();
/******/
/******/ /* webpack/runtime/global */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions test/cases/contenthash-1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* eslint-disable */
async () => await import("./lib.js");
import "./style.css";
Empty file added test/cases/contenthash-1/lib.js
Empty file.
Empty file.
25 changes: 25 additions & 0 deletions test/cases/contenthash-1/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Self from "../../../src";

module.exports = {
entry: "./index.js",
mode: "production",
cache: {
type: "filesystem",
},
module: {
rules: [
{
test: /\.css$/,
use: [Self.loader, "css-loader"],
},
],
},
output: {
filename: "[name].[contenthash].js",
},
plugins: [
new Self({
filename: "[name].[contenthash].css",
}),
],
};
18 changes: 18 additions & 0 deletions test/cases/hmr/expected/main.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
/*!****************************************************************!*\
!*** css ../../../node_modules/css-loader/dist/cjs.js!./c.css ***!
\****************************************************************/
@import url(https://some/other/external/css);
/*!****************************************************************!*\
!*** css ../../../node_modules/css-loader/dist/cjs.js!./b.css ***!
\****************************************************************/
@import url(https://some/external/css);
/*!****************************************************************!*\
!*** css ../../../node_modules/css-loader/dist/cjs.js!./a.css ***!
\****************************************************************/
body {
background: red;
}

/*!********************************************************************!*\
!*** css ../../../node_modules/css-loader/dist/cjs.js!./c.css (1) ***!
\********************************************************************/
.c {
background: red;
}
Expand All @@ -12,6 +24,9 @@ body {
color: yellow;
}

/*!********************************************************************!*\
!*** css ../../../node_modules/css-loader/dist/cjs.js!./b.css (1) ***!
\********************************************************************/
.b {
background: red;
}
Expand All @@ -20,5 +35,8 @@ body {
color: yellow;
}

/*!********************************************************************!*\
!*** css ../../../node_modules/css-loader/dist/cjs.js!./index.css ***!
\********************************************************************/


61 changes: 37 additions & 24 deletions test/cases/hmr/expected/main.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ([
/* 0 */
/***/ ((module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
// extracted by mini-css-extract-plugin

if(true) {
//
var cssReload = __webpack_require__(1)(module.id, {"locals":false});
module.hot.dispose(cssReload);
module.hot.accept(undefined, cssReload);
}

/******/ var __webpack_modules__ = ({

/***/ }),
/* 1 */
/***/ "../../../src/hmr/hotModuleReplacement.js":
/*!************************************************!*\
!*** ../../../src/hmr/hotModuleReplacement.js ***!
\************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {

/* eslint-env browser */
Expand All @@ -26,7 +14,7 @@ __webpack_require__.r(__webpack_exports__);
func-names
*/

const normalizeUrl = __webpack_require__(2);
const normalizeUrl = __webpack_require__(/*! ./normalize-url */ "../../../src/hmr/normalize-url.js");

const srcByModuleId = Object.create(null);

Expand Down Expand Up @@ -262,7 +250,11 @@ module.exports = function (moduleId, options) {


/***/ }),
/* 2 */

/***/ "../../../src/hmr/normalize-url.js":
/*!*****************************************!*\
!*** ../../../src/hmr/normalize-url.js ***!
\*****************************************/
/***/ ((module) => {

/* eslint-disable */
Expand Down Expand Up @@ -305,8 +297,29 @@ module.exports = function (urlString) {
};


/***/ }),

/***/ "./index.css":
/*!*******************!*\
!*** ./index.css ***!
\*******************/
/***/ ((module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
// extracted by mini-css-extract-plugin

if(true) {
//
var cssReload = __webpack_require__(/*! ../../../src/hmr/hotModuleReplacement.js */ "../../../src/hmr/hotModuleReplacement.js")(module.id, {"locals":false});
module.hot.dispose(cssReload);
module.hot.accept(undefined, cssReload);
}


/***/ })
/******/ ]);

/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
Expand Down Expand Up @@ -362,10 +375,10 @@ module.exports = function (urlString) {
/******/
/******/ /* webpack/runtime/get mini-css chunk filename */
/******/ (() => {
/******/ // This function allow to reference all chunks
/******/ // This function allow to reference async chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "" + "main" + ".css";
/******/ return undefined;
/******/ };
/******/ })();
/******/
Expand Down Expand Up @@ -947,7 +960,7 @@ module.exports = function (urlString) {
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
/******/ var installedChunks = __webpack_require__.hmrS_jsonp = __webpack_require__.hmrS_jsonp || {
/******/ 0: 0
/******/ "main": 0
/******/ };
/******/
/******/ // no chunk on demand loading
Expand Down Expand Up @@ -1457,7 +1470,7 @@ module.exports = function (urlString) {
/******/ // module cache are used so entry inlining is disabled
/******/ // startup
/******/ // Load entry module and return exports
/******/ var __webpack_exports__ = __webpack_require__(0);
/******/ var __webpack_exports__ = __webpack_require__("./index.css");
/******/
/******/ })()
;
1 change: 1 addition & 0 deletions test/cases/hmr/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Self from "../../../src";
module.exports = {
entry: "./index.css",
mode: "development",
devtool: false,
module: {
rules: [
{
Expand Down
2 changes: 1 addition & 1 deletion test/cases/insert-function/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
/******/
/******/ /* webpack/runtime/get mini-css chunk filename */
/******/ (() => {
/******/ // This function allow to reference all chunks
/******/ // This function allow to reference async chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "" + chunkId + ".css";
Expand Down
2 changes: 1 addition & 1 deletion test/cases/insert-string/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
/******/
/******/ /* webpack/runtime/get mini-css chunk filename */
/******/ (() => {
/******/ // This function allow to reference all chunks
/******/ // This function allow to reference async chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "" + chunkId + ".css";
Expand Down
2 changes: 1 addition & 1 deletion test/cases/insert-undefined/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
/******/
/******/ /* webpack/runtime/get mini-css chunk filename */
/******/ (() => {
/******/ // This function allow to reference all chunks
/******/ // This function allow to reference async chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "" + chunkId + ".css";
Expand Down
4 changes: 2 additions & 2 deletions test/cases/runtime/expected/runtime~main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@
/******/
/******/ /* webpack/runtime/get mini-css chunk filename */
/******/ (() => {
/******/ // This function allow to reference all chunks
/******/ // This function allow to reference async chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "" + "main" + "." + "a45a4571ab5cece12cf0" + ".css";
/******/ return undefined;
/******/ };
/******/ })();
/******/
Expand Down