Skip to content

Commit b7e5b78

Browse files
chenzhiyongSingle-Dancer
authored andcommitted
fix(loader): 缓存Page 和 App 源码的同时也对 sourcemap 进行缓存,并将其传递下去,避免 sourcemap 链断裂
1 parent 66cef71 commit b7e5b78

File tree

7 files changed

+35
-16
lines changed

7 files changed

+35
-16
lines changed

packages/taro-loader/src/app.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { stringifyRequest } from './util'
66

77
import type * as webpack from 'webpack'
88

9-
export default function (this: webpack.LoaderContext<any>, source: string) {
9+
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
1010
const stringify = (s: string): string => stringifyRequest(this, s)
11-
1211
const options = this.getOptions()
1312
const { importFrameworkStatement, frameworkArgs, creator, creatorLocation, modifyInstantiate } = options.loaderMeta
1413
const config = JSON.stringify(options.config)
@@ -17,7 +16,10 @@ export default function (this: webpack.LoaderContext<any>, source: string) {
1716
const pxTransformConfig = options.pxTransformConfig
1817
const { globalObject } = this._compilation?.outputOptions || { globalObject: 'wx' }
1918
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + '?name=app'
20-
entryCache.set('app', source)
19+
entryCache.set('app', {
20+
source,
21+
map
22+
})
2123

2224
const prerender = `
2325
if (typeof PRERENDER !== 'undefined') {

packages/taro-loader/src/component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import { stringifyRequest } from './util'
55

66
import type * as webpack from 'webpack'
77

8-
export default function (this: webpack.LoaderContext<any>, source: string) {
8+
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
99
const options = this.getOptions()
1010
const stringify = (s: string): string => stringifyRequest(this, s)
1111
const pageName = options.name
1212
const { isNeedRawLoader } = options.loaderMeta
1313
// raw is a placeholder loader to locate changed .vue resource
1414
const raw = path.join(__dirname, 'raw.js')
1515
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + `?name=${pageName}`
16-
entryCache.set(pageName, source)
16+
entryCache.set(pageName, {
17+
source,
18+
map
19+
})
1720
const componentPath = isNeedRawLoader
1821
? ['!', raw, entryCacheLoader, this.resourcePath].join('!')
1922
: ['!', entryCacheLoader, this.resourcePath].join('!')
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
export const entryCache = new Map<string, string>()
1+
export const entryCache = new Map<string, any>()
22

33
export default function () {
4+
const callback = this.async()
45
const { name } = this.getOptions()
56
if (name && entryCache.has(name)) {
67
const content = entryCache.get(name)
7-
entryCache.delete(name)
8-
return content
8+
// just in case, delete cache in next tick
9+
setImmediate(() => entryCache.delete(name))
10+
callback(null, content!.source, content!.map)
911
}
1012
}

packages/taro-loader/src/independentPage.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface PageConfig {
1111
path: string
1212
}
1313

14-
export default function (this: webpack.LoaderContext<any>, source: string) {
14+
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
1515
const options = this.getOptions()
1616
const config = getPageConfig(options.config, this.resourcePath)
1717
const configString = JSON.stringify(config)
@@ -31,7 +31,10 @@ export default function (this: webpack.LoaderContext<any>, source: string) {
3131
const frameworkArgsCopy = frameworkArgsArray.join(',')
3232
// raw is a placeholder loader to locate changed .vue resource
3333
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + `?name=${pageName}`
34-
entryCache.set(pageName, source)
34+
entryCache.set(pageName, {
35+
source,
36+
map
37+
})
3538
const raw = path.join(__dirname, 'raw.js')
3639
const componentPath = isNeedRawLoader
3740
? ['!', raw, entryCacheLoader, this.resourcePath].join('!')

packages/taro-loader/src/native-component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { stringifyRequest } from './util'
66

77
import type * as webpack from 'webpack'
88

9-
export default function (this: webpack.LoaderContext<any>, source: string) {
9+
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
1010
const options = this.getOptions()
1111
const { loaderMeta = {}, config: loaderConfig, isNewBlended = false, runtimePath } = options
1212
const { importFrameworkStatement, frameworkArgs, isNeedRawLoader, creatorLocation } = loaderMeta
@@ -18,7 +18,10 @@ export default function (this: webpack.LoaderContext<any>, source: string) {
1818
const behaviorsName = options.behaviorsName
1919
// raw is a placeholder loader to locate changed .vue resource
2020
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + `?name=${pageName}`
21-
entryCache.set(pageName, source)
21+
entryCache.set(pageName, {
22+
source,
23+
map
24+
})
2225
const raw = path.join(__dirname, 'raw.js')
2326
const componentPath = isNeedRawLoader
2427
? ['!', raw, entryCacheLoader, this.resourcePath].join('!')

packages/taro-loader/src/native-page.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { stringifyRequest } from './util'
66

77
import type * as webpack from 'webpack'
88

9-
export default function (this: webpack.LoaderContext<any>, source: string) {
9+
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
1010
const options = this.getOptions()
1111
const { importFrameworkStatement, frameworkArgs, isNeedRawLoader, creatorLocation } = options.loaderMeta
1212
const { config: loaderConfig } = options
@@ -17,7 +17,10 @@ export default function (this: webpack.LoaderContext<any>, source: string) {
1717
const behaviorsName = options.behaviorsName
1818
// raw is a placeholder loader to locate changed .vue resource
1919
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + `?name=${pageName}`
20-
entryCache.set(pageName, source)
20+
entryCache.set(pageName, {
21+
source,
22+
map
23+
})
2124
const raw = path.join(__dirname, 'raw.js')
2225
const componentPath = isNeedRawLoader
2326
? ['!', raw, entryCacheLoader, this.resourcePath].join('!')

packages/taro-loader/src/page.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface PageConfig {
1212
path: string
1313
}
1414

15-
export default function (this: webpack.LoaderContext<any>, source: string) {
15+
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
1616
const options = this.getOptions()
1717
const { config: loaderConfig } = options
1818
const config = getPageConfig(loaderConfig, this.resourcePath)
@@ -23,7 +23,10 @@ export default function (this: webpack.LoaderContext<any>, source: string) {
2323
const { isNeedRawLoader, modifyInstantiate } = options.loaderMeta
2424
// raw is a placeholder loader to locate changed .vue resource
2525
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + `?name=${pageName}`
26-
entryCache.set(pageName, source)
26+
entryCache.set(pageName, {
27+
source,
28+
map
29+
})
2730
const raw = path.join(__dirname, 'raw.js')
2831
const componentPath = isNeedRawLoader
2932
? ['!', raw, entryCacheLoader, this.resourcePath].join('!')

0 commit comments

Comments
 (0)