Skip to content

Commit 927df9f

Browse files
committed
Fix HMR for Vue
1 parent f0bc4cc commit 927df9f

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

packages/app/src/sandbox/eval/transpiled-module.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export type LoaderContext = {
7777
title: string,
7878
code: string,
7979
currentPath?: string,
80-
overwrite?: boolean
80+
overwrite?: boolean,
81+
isChild?: boolean
8182
) => TranspiledModule,
8283
emitFile: (name: string, content: string, sourceMap: SourceMap) => void,
8384
options: {
@@ -249,6 +250,7 @@ export default class TranspiledModule {
249250
}
250251

251252
resetTranspilation() {
253+
console.log('resetting', this);
252254
Array.from(this.transpilationInitiators)
253255
.filter(t => t.source)
254256
.forEach(dep => {
@@ -432,7 +434,8 @@ export default class TranspiledModule {
432434
path: string,
433435
code: string,
434436
directoryPath: string = pathUtils.dirname(this.module.path),
435-
overwrite?: boolean = true
437+
overwrite?: boolean = true,
438+
isChild?: boolean = true
436439
) => {
437440
const queryPath = path.split('!');
438441
// pop() mutates queryPath, queryPath is now just the loaders
@@ -463,7 +466,9 @@ export default class TranspiledModule {
463466
transpiledModule ||
464467
manager.addTranspiledModule(moduleCopy, queryPath.join('!'));
465468

466-
this.childModules.push(transpiledModule);
469+
if (isChild) {
470+
this.childModules.push(transpiledModule);
471+
}
467472
this.dependencies.add(transpiledModule);
468473
transpiledModule.initiators.add(this);
469474

@@ -798,6 +803,7 @@ export default class TranspiledModule {
798803
}
799804

800805
const hotData = this.hmrConfig ? this.hmrConfig.data : undefined;
806+
console.log(hotData);
801807

802808
this.compilation = this.compilation || {
803809
id: this.getId(),
@@ -1118,4 +1124,4 @@ export default class TranspiledModule {
11181124
this.asyncDependencies.push(Promise.resolve(loadModule(depId)));
11191125
});
11201126
}
1121-
}
1127+
}

packages/app/src/sandbox/eval/transpilers/vue/css-loader/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function transpile(
1313
content: string,
1414
loaderContext: LoaderContext
1515
) {
16-
loaderContext.emitModule(CSSBasePath, CSSBaseRaw, '/', false);
16+
loaderContext.emitModule(CSSBasePath, CSSBaseRaw, '/', false, false);
1717

1818
let result = '';
1919
result += `exports = module.exports = require("${CSSBasePath}")(false);\n\n`;

packages/app/src/sandbox/eval/transpilers/vue/loader.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ const rewriterInjectRE = /\b(css(?:-loader)?(?:\?[^!]+)?)(?:!|$)/;
3737

3838
export default function(content: string, loaderContext: LoaderContext) {
3939
// Emit the vue-hot-reload-api so it's available in the sandbox
40-
loaderContext.emitModule(hotReloadAPIPath, vueHotReloadAPIRaw, '/', false);
40+
loaderContext.emitModule(
41+
hotReloadAPIPath,
42+
vueHotReloadAPIRaw,
43+
'/',
44+
false,
45+
false
46+
);
4147

4248
const { path, _module } = loaderContext;
4349
const query = loaderContext.options;
@@ -213,6 +219,7 @@ export default function(content: string, loaderContext: LoaderContext) {
213219
'!noop-loader!/node_modules/component-normalizer.js',
214220
componentNormalizerRaw,
215221
'/',
222+
false,
216223
false
217224
);
218225

@@ -403,7 +410,7 @@ export default function(content: string, loaderContext: LoaderContext) {
403410
// getFileName(type, part, index);
404411
rawRequest;
405412

406-
// loaderContext.emitModule(rawPath, part.content, dirname(filePath), false);
413+
// loaderContext.emitModule(rawPath, part.content, dirname(filePath), false, false);
407414

408415
const depPath = loaderUtils.stringifyRequest(loaderContext, rawPath);
409416
loaderContext.addDependency(JSON.parse(depPath));

packages/app/src/sandbox/eval/transpilers/vue/style-loader/loader.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,20 @@ export default function(content: string, loaderContext) {
1717
const isServer = false;
1818
const isProduction = false;
1919

20-
loaderContext.emitModule(addStylesClientPath, addStylesClientRaw, '/', false);
21-
loaderContext.emitModule(listToStylesPath, listToStylesRaw, '/', false);
20+
loaderContext.emitModule(
21+
addStylesClientPath,
22+
addStylesClientRaw,
23+
'/',
24+
false,
25+
false
26+
);
27+
loaderContext.emitModule(
28+
listToStylesPath,
29+
listToStylesRaw,
30+
'/',
31+
false,
32+
false
33+
);
2234

2335
const request = loaderUtils.stringifyRequest(
2436
loaderContext,

packages/app/src/sandbox/eval/transpilers/vue/template-compiler/loader.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import transformSrcset from './modules/transform-srcset';
99

1010
const hotReloadAPIPath = '!noop-loader!/node_modules/vue-hot-reload-api.js';
1111
export default function(html: string, loaderContext: LoaderContext) {
12-
loaderContext.emitModule(hotReloadAPIPath, vueHotReloadAPIRaw, '/', false);
12+
loaderContext.emitModule(
13+
hotReloadAPIPath,
14+
vueHotReloadAPIRaw,
15+
'/',
16+
false,
17+
false
18+
);
1319

1420
const options = loaderContext.options;
1521
const vueOptions = options.vueOptions || {};

0 commit comments

Comments
 (0)