Skip to content

Commit c76a1a1

Browse files
feat: added new url support (#753)
1 parent 4227510 commit c76a1a1

File tree

28 files changed

+146
-12
lines changed

28 files changed

+146
-12
lines changed

package-lock.json

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"npm-run-all": "^4.1.5",
7474
"prettier": "^2.2.1",
7575
"standard-version": "^9.1.0",
76-
"webpack": "^5.33.2",
76+
"webpack": "^5.36.1",
7777
"webpack-cli": "^4.5.0",
7878
"webpack-dev-server": "^3.7.2"
7979
},

src/loader.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export function pitch(request) {
196196
);
197197
return;
198198
}
199+
199200
this.importModule(
200201
`${this.resourcePath}.webpack[javascript/auto]!=!${request}`,
201202
{
@@ -230,6 +231,18 @@ export function pitch(request) {
230231
outputOptions
231232
);
232233

234+
// The templates are compiled and executed by NodeJS - similar to server side rendering
235+
// Unfortunately this causes issues as some loaders require an absolute URL to support ES Modules
236+
// The following config enables relative URL support for the child compiler
237+
childCompiler.options.module = { ...childCompiler.options.module };
238+
childCompiler.options.module.parser = {
239+
...childCompiler.options.module.parser,
240+
};
241+
childCompiler.options.module.parser.javascript = {
242+
...childCompiler.options.module.parser.javascript,
243+
url: 'relative',
244+
};
245+
233246
const { NodeTemplatePlugin } = webpack.node;
234247
const NodeTargetPlugin = webpack.node.NodeTargetPlugin
235248
? webpack.node.NodeTargetPlugin

test/TestCases.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ describe('TestCases', () => {
106106
directoryForCase,
107107
'webpack.config.js'
108108
));
109+
const { context } = webpackConfig;
109110

110111
for (const config of [].concat(webpackConfig)) {
111112
Object.assign(
@@ -132,7 +133,8 @@ describe('TestCases', () => {
132133
}
133134
return p;
134135
}),
135-
}
136+
},
137+
context ? { context } : {}
136138
);
137139
}
138140

test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
7373
/******/
7474
/******/ /* webpack/runtime/getFullHash */
7575
/******/ (() => {
76-
/******/ __webpack_require__.h = () => ("acd0bc1ae24d05fdac73")
76+
/******/ __webpack_require__.h = () => ("619e4b98882ea3a2aba3")
7777
/******/ })();
7878
/******/
7979
/******/ /* webpack/runtime/global */

test/cases/chunkFilename-fullhash/expected/webpack-5/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
7373
/******/
7474
/******/ /* webpack/runtime/getFullHash */
7575
/******/ (() => {
76-
/******/ __webpack_require__.h = () => ("4ecab8e2ff0fe228a728")
76+
/******/ __webpack_require__.h = () => ("962555dd7355e6c261df")
7777
/******/ })();
7878
/******/
7979
/******/ /* webpack/runtime/global */

0 commit comments

Comments
 (0)