Skip to content
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
8 changes: 5 additions & 3 deletions packages/taro-loader/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { stringifyRequest } from './util'

import type * as webpack from 'webpack'

export default function (this: webpack.LoaderContext<any>, source: string) {
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
const stringify = (s: string): string => stringifyRequest(this, s)

const options = this.getOptions()
const { importFrameworkStatement, frameworkArgs, creator, creatorLocation, modifyInstantiate } = options.loaderMeta
const config = JSON.stringify(options.config)
Expand All @@ -17,7 +16,10 @@ export default function (this: webpack.LoaderContext<any>, source: string) {
const pxTransformConfig = options.pxTransformConfig
const { globalObject } = this._compilation?.outputOptions || { globalObject: 'wx' }
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + '?name=app'
entryCache.set('app', source)
entryCache.set('app', {
source,
map
})

const prerender = `
if (typeof PRERENDER !== 'undefined') {
Expand Down
7 changes: 5 additions & 2 deletions packages/taro-loader/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { stringifyRequest } from './util'

import type * as webpack from 'webpack'

export default function (this: webpack.LoaderContext<any>, source: string) {
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
const options = this.getOptions()
const stringify = (s: string): string => stringifyRequest(this, s)
const pageName = options.name
const { isNeedRawLoader } = options.loaderMeta
// raw is a placeholder loader to locate changed .vue resource
const raw = path.join(__dirname, 'raw.js')
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + `?name=${pageName}`
entryCache.set(pageName, source)
entryCache.set(pageName, {
source,
map
})
const componentPath = isNeedRawLoader
? ['!', raw, entryCacheLoader, this.resourcePath].join('!')
: ['!', entryCacheLoader, this.resourcePath].join('!')
Expand Down
8 changes: 5 additions & 3 deletions packages/taro-loader/src/entry-cache.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export const entryCache = new Map<string, string>()
export const entryCache = new Map<string, any>()

export default function () {
const callback = this.async()
const { name } = this.getOptions()
if (name && entryCache.has(name)) {
const content = entryCache.get(name)
entryCache.delete(name)
return content
// just in case, delete cache in next tick
setImmediate(() => entryCache.delete(name))
callback(null, content!.source, content!.map)
}
}
7 changes: 5 additions & 2 deletions packages/taro-loader/src/independentPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface PageConfig {
path: string
}

export default function (this: webpack.LoaderContext<any>, source: string) {
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
const options = this.getOptions()
const config = getPageConfig(options.config, this.resourcePath)
const configString = JSON.stringify(config)
Expand All @@ -31,7 +31,10 @@ export default function (this: webpack.LoaderContext<any>, source: string) {
const frameworkArgsCopy = frameworkArgsArray.join(',')
// raw is a placeholder loader to locate changed .vue resource
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + `?name=${pageName}`
entryCache.set(pageName, source)
entryCache.set(pageName, {
source,
map
})
const raw = path.join(__dirname, 'raw.js')
const componentPath = isNeedRawLoader
? ['!', raw, entryCacheLoader, this.resourcePath].join('!')
Expand Down
7 changes: 5 additions & 2 deletions packages/taro-loader/src/native-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { stringifyRequest } from './util'

import type * as webpack from 'webpack'

export default function (this: webpack.LoaderContext<any>, source: string) {
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
const options = this.getOptions()
const { loaderMeta = {}, config: loaderConfig, isNewBlended = false, runtimePath } = options
const { importFrameworkStatement, frameworkArgs, isNeedRawLoader, creatorLocation } = loaderMeta
Expand All @@ -18,7 +18,10 @@ export default function (this: webpack.LoaderContext<any>, source: string) {
const behaviorsName = options.behaviorsName
// raw is a placeholder loader to locate changed .vue resource
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + `?name=${pageName}`
entryCache.set(pageName, source)
entryCache.set(pageName, {
source,
map
})
const raw = path.join(__dirname, 'raw.js')
const componentPath = isNeedRawLoader
? ['!', raw, entryCacheLoader, this.resourcePath].join('!')
Expand Down
7 changes: 5 additions & 2 deletions packages/taro-loader/src/native-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { stringifyRequest } from './util'

import type * as webpack from 'webpack'

export default function (this: webpack.LoaderContext<any>, source: string) {
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
const options = this.getOptions()
const { importFrameworkStatement, frameworkArgs, isNeedRawLoader, creatorLocation } = options.loaderMeta
const { config: loaderConfig } = options
Expand All @@ -17,7 +17,10 @@ export default function (this: webpack.LoaderContext<any>, source: string) {
const behaviorsName = options.behaviorsName
// raw is a placeholder loader to locate changed .vue resource
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + `?name=${pageName}`
entryCache.set(pageName, source)
entryCache.set(pageName, {
source,
map
})
const raw = path.join(__dirname, 'raw.js')
const componentPath = isNeedRawLoader
? ['!', raw, entryCacheLoader, this.resourcePath].join('!')
Expand Down
7 changes: 5 additions & 2 deletions packages/taro-loader/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface PageConfig {
path: string
}

export default function (this: webpack.LoaderContext<any>, source: string) {
export default function (this: webpack.LoaderContext<any>, source: string, map?: any) {
const options = this.getOptions()
const { config: loaderConfig } = options
const config = getPageConfig(loaderConfig, this.resourcePath)
Expand All @@ -23,7 +23,10 @@ export default function (this: webpack.LoaderContext<any>, source: string) {
const { isNeedRawLoader, modifyInstantiate } = options.loaderMeta
// raw is a placeholder loader to locate changed .vue resource
const entryCacheLoader = path.join(__dirname, 'entry-cache.js') + `?name=${pageName}`
entryCache.set(pageName, source)
entryCache.set(pageName, {
source,
map
})
const raw = path.join(__dirname, 'raw.js')
const componentPath = isNeedRawLoader
? ['!', raw, entryCacheLoader, this.resourcePath].join('!')
Expand Down