@wyw-in-js/webpack-loader 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +7 -7
- package/types/index.d.ts +3 -2
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["path","logger","transform","TransformCacheCollection","sharedState","getCacheInstance","WYWinJSDebugPlugin","outputCssLoader","require","resolve","cache","webpack5Loader","webpack5LoaderPlugin","content","inputSourceMap","convertSourceMap","value","filename","undefined","file","mappings","names","sources","version","async","resourcePath","sourceMap","preprocessor","extension","cacheProvider","rest","getOptions","outputFileName","replace","resolveModule","getResolve","dependencyType","asyncResolve","token","importer","context","isAbsolute","dirname","join","process","cwd","Promise","reject","err","result","addDependency","Error","transformServices","options","root","pluginOptions","eventEmitter","emitter","toString","then","cssText","Buffer","from","cssSourceMapText","all","dependencies","map","dep","cacheInstance","set","setDependencies","getDependencies","request","encodeURIComponent","stringifiedRequest","JSON","stringify","utils","contextify","rootContext","callback","code","catch"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * This file contains a Webpack loader for WYW-in-JS.\n * It uses the transform.ts function to generate class names from source code,\n * returns transformed code without template literals and attaches generated source maps\n */\n\nimport path from 'path';\n\nimport type { RawSourceMap } from 'source-map';\nimport type { RawLoaderDefinitionFunction } from 'webpack';\n\nimport { logger } from '@wyw-in-js/shared';\nimport type { Preprocessor, Result } from '@wyw-in-js/transform';\nimport { transform, TransformCacheCollection } from '@wyw-in-js/transform';\n\nimport { sharedState } from './WYWinJSDebugPlugin';\nimport type { ICache } from './cache';\nimport { getCacheInstance } from './cache';\n\nexport { WYWinJSDebugPlugin } from './WYWinJSDebugPlugin';\n\nconst outputCssLoader = require.resolve('./outputCssLoader');\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":["path","logger","transform","TransformCacheCollection","sharedState","getCacheInstance","WYWinJSDebugPlugin","outputCssLoader","require","resolve","cache","webpack5Loader","webpack5LoaderPlugin","content","inputSourceMap","convertSourceMap","value","filename","undefined","file","mappings","names","sources","version","async","resourcePath","sourceMap","preprocessor","extension","cacheProvider","rest","getOptions","outputFileName","replace","resolveModule","getResolve","dependencyType","asyncResolve","token","importer","context","isAbsolute","dirname","join","process","cwd","Promise","reject","err","result","addDependency","Error","transformServices","options","root","pluginOptions","eventEmitter","emitter","toString","then","cssText","Buffer","from","cssSourceMapText","all","dependencies","map","dep","cacheInstance","set","setDependencies","getDependencies","request","encodeURIComponent","stringifiedRequest","JSON","stringify","utils","contextify","rootContext","callback","code","catch"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * This file contains a Webpack loader for WYW-in-JS.\n * It uses the transform.ts function to generate class names from source code,\n * returns transformed code without template literals and attaches generated source maps\n */\n\nimport path from 'path';\n\nimport type { RawSourceMap } from 'source-map';\nimport type { RawLoaderDefinitionFunction } from 'webpack';\n\nimport { logger } from '@wyw-in-js/shared';\nimport type { Preprocessor, Result } from '@wyw-in-js/transform';\nimport { transform, TransformCacheCollection } from '@wyw-in-js/transform';\n\nimport { sharedState } from './WYWinJSDebugPlugin';\nimport type { ICache } from './cache';\nimport { getCacheInstance } from './cache';\n\nexport { WYWinJSDebugPlugin } from './WYWinJSDebugPlugin';\n\nconst outputCssLoader = require.resolve('./outputCssLoader');\n\nexport type LoaderOptions = {\n cacheProvider?: string | ICache;\n extension?: string;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n};\ntype Loader = RawLoaderDefinitionFunction<LoaderOptions>;\n\nconst cache = new TransformCacheCollection();\n\nconst webpack5Loader: Loader = function webpack5LoaderPlugin(\n content,\n inputSourceMap\n) {\n function convertSourceMap(\n value: typeof inputSourceMap,\n filename: string\n ): RawSourceMap | undefined {\n if (typeof value === 'string' || !value) {\n return undefined;\n }\n\n return {\n ...value,\n file: value.file ?? filename,\n mappings: value.mappings ?? '',\n names: value.names ?? [],\n sources: value.sources ?? [],\n version: value.version ?? 3,\n };\n }\n\n // tell Webpack this loader is async\n this.async();\n\n logger('loader %s', this.resourcePath);\n\n const {\n sourceMap = undefined,\n preprocessor = undefined,\n extension = '.wyw-in-js.css',\n cacheProvider,\n ...rest\n } = this.getOptions() || {};\n\n const outputFileName = this.resourcePath.replace(/\\.[^.]+$/, extension);\n const resolveModule = this.getResolve({ dependencyType: 'esm' });\n\n const asyncResolve = (token: string, importer: string): Promise<string> => {\n const context = path.isAbsolute(importer)\n ? path.dirname(importer)\n : path.join(process.cwd(), path.dirname(importer));\n return new Promise((resolve, reject) => {\n resolveModule(context, token, (err, result) => {\n if (err) {\n reject(err);\n } else if (result) {\n this.addDependency(result);\n resolve(result);\n } else {\n reject(new Error(`Cannot resolve ${token}`));\n }\n });\n });\n };\n\n const transformServices = {\n options: {\n filename: this.resourcePath,\n inputSourceMap: convertSourceMap(inputSourceMap, this.resourcePath),\n root: process.cwd(),\n preprocessor,\n pluginOptions: rest,\n },\n cache,\n eventEmitter: sharedState.emitter,\n };\n\n transform(transformServices, content.toString(), asyncResolve)\n .then(\n async (result: Result) => {\n if (result.cssText) {\n let { cssText } = result;\n\n if (sourceMap) {\n cssText += `/*# sourceMappingURL=data:application/json;base64,${Buffer.from(\n result.cssSourceMapText || ''\n ).toString('base64')}*/`;\n }\n\n await Promise.all(\n result.dependencies?.map((dep) =>\n asyncResolve(dep, this.resourcePath)\n ) ?? []\n );\n\n try {\n const cacheInstance = await getCacheInstance(cacheProvider);\n\n await cacheInstance.set(this.resourcePath, cssText);\n\n await cacheInstance.setDependencies?.(\n this.resourcePath,\n this.getDependencies()\n );\n\n const request = `${outputFileName}!=!${outputCssLoader}?cacheProvider=${encodeURIComponent(\n typeof cacheProvider === 'string' ? cacheProvider : ''\n )}!${this.resourcePath}`;\n const stringifiedRequest = JSON.stringify(\n this.utils.contextify(this.context || this.rootContext, request)\n );\n\n this.callback(\n null,\n `${result.code}\\n\\nrequire(${stringifiedRequest});`,\n result.sourceMap ?? undefined\n );\n } catch (err) {\n this.callback(err as Error);\n }\n\n return;\n }\n\n this.callback(null, result.code, result.sourceMap ?? undefined);\n },\n (err: Error) => this.callback(err)\n )\n .catch((err: Error) => this.callback(err));\n};\n\nexport default webpack5Loader;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,MAAM;AAKvB,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,SAASC,SAAS,EAAEC,wBAAwB,QAAQ,sBAAsB;AAE1E,SAASC,WAAW,QAAQ,sBAAsB;AAElD,SAASC,gBAAgB,QAAQ,SAAS;AAE1C,SAASC,kBAAkB,QAAQ,sBAAsB;AAEzD,MAAMC,eAAe,GAAGC,OAAO,CAACC,OAAO,CAAC,mBAAmB,CAAC;AAU5D,MAAMC,KAAK,GAAG,IAAIP,wBAAwB,CAAC,CAAC;AAE5C,MAAMQ,cAAsB,GAAG,SAASC,oBAAoBA,CAC1DC,OAAO,EACPC,cAAc,EACd;EACA,SAASC,gBAAgBA,CACvBC,KAA4B,EAC5BC,QAAgB,EACU;IAC1B,IAAI,OAAOD,KAAK,KAAK,QAAQ,IAAI,CAACA,KAAK,EAAE;MACvC,OAAOE,SAAS;IAClB;IAEA,OAAO;MACL,GAAGF,KAAK;MACRG,IAAI,EAAEH,KAAK,CAACG,IAAI,IAAIF,QAAQ;MAC5BG,QAAQ,EAAEJ,KAAK,CAACI,QAAQ,IAAI,EAAE;MAC9BC,KAAK,EAAEL,KAAK,CAACK,KAAK,IAAI,EAAE;MACxBC,OAAO,EAAEN,KAAK,CAACM,OAAO,IAAI,EAAE;MAC5BC,OAAO,EAAEP,KAAK,CAACO,OAAO,IAAI;IAC5B,CAAC;EACH;;EAEA;EACA,IAAI,CAACC,KAAK,CAAC,CAAC;EAEZvB,MAAM,CAAC,WAAW,EAAE,IAAI,CAACwB,YAAY,CAAC;EAEtC,MAAM;IACJC,SAAS,GAAGR,SAAS;IACrBS,YAAY,GAAGT,SAAS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C,WAAW,EAAEP,OAAO,CACjE,CAAC;QAED,IAAI,CAACQ,QAAQ,CACX,IAAI,EACH,GAAE/B,MAAM,CAACgC,IAAK,eAAcP,kBAAmB,IAAG,EACnDzB,MAAM,CAACvB,SAAS,IAAIR,SACtB,CAAC;MACH,CAAC,CAAC,OAAO8B,GAAG,EAAE;QACZ,IAAI,CAACgC,QAAQ,CAAChC,GAAY,CAAC;MAC7B;MAEA;IACF;IAEA,IAAI,CAACgC,QAAQ,CAAC,IAAI,EAAE/B,MAAM,CAACgC,IAAI,EAAEhC,MAAM,CAACvB,SAAS,IAAIR,SAAS,CAAC;EACjE,CAAC,EACA8B,GAAU,IAAK,IAAI,CAACgC,QAAQ,CAAChC,GAAG,CACnC,CAAC,CACAkC,KAAK,CAAElC,GAAU,IAAK,IAAI,CAACgC,QAAQ,CAAChC,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED,eAAerC,cAAc"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_path","_interopRequireDefault","require","_shared","_transform","_WYWinJSDebugPlugin","_cache","obj","__esModule","default","outputCssLoader","resolve","cache","TransformCacheCollection","webpack5Loader","webpack5LoaderPlugin","content","inputSourceMap","convertSourceMap","value","filename","_value$file","_value$mappings","_value$names","_value$sources","_value$version","undefined","file","mappings","names","sources","version","async","logger","resourcePath","sourceMap","preprocessor","extension","cacheProvider","rest","getOptions","outputFileName","replace","resolveModule","getResolve","dependencyType","asyncResolve","token","importer","context","path","isAbsolute","dirname","join","process","cwd","Promise","reject","err","result","addDependency","Error","transformServices","options","root","pluginOptions","eventEmitter","sharedState","emitter","transform","toString","then","_result$sourceMap2","cssText","_result$dependencies$","_result$dependencies","Buffer","from","cssSourceMapText","all","dependencies","map","dep","_cacheInstance$setDep","_result$sourceMap","cacheInstance","getCacheInstance","set","setDependencies","call","getDependencies","request","encodeURIComponent","stringifiedRequest","JSON","stringify","utils","contextify","rootContext","callback","code","catch","_default","exports"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * This file contains a Webpack loader for WYW-in-JS.\n * It uses the transform.ts function to generate class names from source code,\n * returns transformed code without template literals and attaches generated source maps\n */\n\nimport path from 'path';\n\nimport type { RawSourceMap } from 'source-map';\nimport type { RawLoaderDefinitionFunction } from 'webpack';\n\nimport { logger } from '@wyw-in-js/shared';\nimport type { Preprocessor, Result } from '@wyw-in-js/transform';\nimport { transform, TransformCacheCollection } from '@wyw-in-js/transform';\n\nimport { sharedState } from './WYWinJSDebugPlugin';\nimport type { ICache } from './cache';\nimport { getCacheInstance } from './cache';\n\nexport { WYWinJSDebugPlugin } from './WYWinJSDebugPlugin';\n\nconst outputCssLoader = require.resolve('./outputCssLoader');\n\ntype Loader = RawLoaderDefinitionFunction<{\n cacheProvider?: string | ICache;\n extension?: string;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n}>;\n\nconst cache = new TransformCacheCollection();\n\nconst webpack5Loader: Loader = function webpack5LoaderPlugin(\n content,\n inputSourceMap\n) {\n function convertSourceMap(\n value: typeof inputSourceMap,\n filename: string\n ): RawSourceMap | undefined {\n if (typeof value === 'string' || !value) {\n return undefined;\n }\n\n return {\n ...value,\n file: value.file ?? filename,\n mappings: value.mappings ?? '',\n names: value.names ?? [],\n sources: value.sources ?? [],\n version: value.version ?? 3,\n };\n }\n\n // tell Webpack this loader is async\n this.async();\n\n logger('loader %s', this.resourcePath);\n\n const {\n sourceMap = undefined,\n preprocessor = undefined,\n extension = '.wyw-in-js.css',\n cacheProvider,\n ...rest\n } = this.getOptions() || {};\n\n const outputFileName = this.resourcePath.replace(/\\.[^.]+$/, extension);\n const resolveModule = this.getResolve({ dependencyType: 'esm' });\n\n const asyncResolve = (token: string, importer: string): Promise<string> => {\n const context = path.isAbsolute(importer)\n ? path.dirname(importer)\n : path.join(process.cwd(), path.dirname(importer));\n return new Promise((resolve, reject) => {\n resolveModule(context, token, (err, result) => {\n if (err) {\n reject(err);\n } else if (result) {\n this.addDependency(result);\n resolve(result);\n } else {\n reject(new Error(`Cannot resolve ${token}`));\n }\n });\n });\n };\n\n const transformServices = {\n options: {\n filename: this.resourcePath,\n inputSourceMap: convertSourceMap(inputSourceMap, this.resourcePath),\n root: process.cwd(),\n preprocessor,\n pluginOptions: rest,\n },\n cache,\n eventEmitter: sharedState.emitter,\n };\n\n transform(transformServices, content.toString(), asyncResolve)\n .then(\n async (result: Result) => {\n if (result.cssText) {\n let { cssText } = result;\n\n if (sourceMap) {\n cssText += `/*# sourceMappingURL=data:application/json;base64,${Buffer.from(\n result.cssSourceMapText || ''\n ).toString('base64')}*/`;\n }\n\n await Promise.all(\n result.dependencies?.map((dep) =>\n asyncResolve(dep, this.resourcePath)\n ) ?? []\n );\n\n try {\n const cacheInstance = await getCacheInstance(cacheProvider);\n\n await cacheInstance.set(this.resourcePath, cssText);\n\n await cacheInstance.setDependencies?.(\n this.resourcePath,\n this.getDependencies()\n );\n\n const request = `${outputFileName}!=!${outputCssLoader}?cacheProvider=${encodeURIComponent(\n typeof cacheProvider === 'string' ? cacheProvider : ''\n )}!${this.resourcePath}`;\n const stringifiedRequest = JSON.stringify(\n this.utils.contextify(this.context || this.rootContext, request)\n );\n\n this.callback(\n null,\n `${result.code}\\n\\nrequire(${stringifiedRequest});`,\n result.sourceMap ?? undefined\n );\n } catch (err) {\n this.callback(err as Error);\n }\n\n return;\n }\n\n this.callback(null, result.code, result.sourceMap ?? undefined);\n },\n (err: Error) => this.callback(err)\n )\n .catch((err: Error) => this.callback(err));\n};\n\nexport default webpack5Loader;\n"],"mappings":";;;;;;;;;;;;AAMA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAA2C,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,U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G,EACtD,CAAE,IAAG,IAAI,CAACJ,YAAa,EAAC;QACxB,MAAM2D,kBAAkB,GAAGC,IAAI,CAACC,SAAS,CACvC,IAAI,CAACC,KAAK,CAACC,UAAU,CAAC,IAAI,CAAChD,OAAO,IAAI,IAAI,CAACiD,WAAW,EAAEP,OAAO,CACjE,CAAC;QAED,IAAI,CAACQ,QAAQ,CACX,IAAI,EACH,GAAExC,MAAM,CAACyC,IAAK,eAAcP,kBAAmB,IAAG,GAAAT,iBAAA,GACnDzB,MAAM,CAACxB,SAAS,cAAAiD,iBAAA,cAAAA,iBAAA,GAAI1D,SACtB,CAAC;MACH,CAAC,CAAC,OAAOgC,GAAG,EAAE;QACZ,IAAI,CAACyC,QAAQ,CAACzC,GAAY,CAAC;MAC7B;MAEA;IACF;IAEA,IAAI,CAACyC,QAAQ,CAAC,IAAI,EAAExC,MAAM,CAACyC,IAAI,GAAA5B,kBAAA,GAAEb,MAAM,CAACxB,SAAS,cAAAqC,kBAAA,cAAAA,kBAAA,GAAI9C,SAAS,CAAC;EACjE,CAAC,EACAgC,GAAU,IAAK,IAAI,CAACyC,QAAQ,CAACzC,GAAG,CACnC,CAAC,CACA2C,KAAK,CAAE3C,GAAU,IAAK,IAAI,CAACyC,QAAQ,CAACzC,GAAG,CAAC,CAAC;AAC9C,CAAC;AAAC,IAAA4C,QAAA,GAAAC,OAAA,CAAA9F,OAAA,GAEaK,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_path","_interopRequireDefault","require","_shared","_transform","_WYWinJSDebugPlugin","_cache","obj","__esModule","default","outputCssLoader","resolve","cache","TransformCacheCollection","webpack5Loader","webpack5LoaderPlugin","content","inputSourceMap","convertSourceMap","value","filename","_value$file","_value$mappings","_value$names","_value$sources","_value$version","undefined","file","mappings","names","sources","version","async","logger","resourcePath","sourceMap","preprocessor","extension","cacheProvider","rest","getOptions","outputFileName","replace","resolveModule","getResolve","dependencyType","asyncResolve","token","importer","context","path","isAbsolute","dirname","join","process","cwd","Promise","reject","err","result","addDependency","Error","transformServices","options","root","pluginOptions","eventEmitter","sharedState","emitter","transform","toString","then","_result$sourceMap2","cssText","_result$dependencies$","_result$dependencies","Buffer","from","cssSourceMapText","all","dependencies","map","dep","_cacheInstance$setDep","_result$sourceMap","cacheInstance","getCacheInstance","set","setDependencies","call","getDependencies","request","encodeURIComponent","stringifiedRequest","JSON","stringify","utils","contextify","rootContext","callback","code","catch","_default","exports"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * This file contains a Webpack loader for WYW-in-JS.\n * It uses the transform.ts function to generate class names from source code,\n * returns transformed code without template literals and attaches generated source maps\n */\n\nimport path from 'path';\n\nimport type { RawSourceMap } from 'source-map';\nimport type { RawLoaderDefinitionFunction } from 'webpack';\n\nimport { logger } from '@wyw-in-js/shared';\nimport type { Preprocessor, Result } from '@wyw-in-js/transform';\nimport { transform, TransformCacheCollection } from '@wyw-in-js/transform';\n\nimport { sharedState } from './WYWinJSDebugPlugin';\nimport type { ICache } from './cache';\nimport { getCacheInstance } from './cache';\n\nexport { WYWinJSDebugPlugin } from './WYWinJSDebugPlugin';\n\nconst outputCssLoader = require.resolve('./outputCssLoader');\n\nexport type LoaderOptions = {\n cacheProvider?: string | ICache;\n extension?: string;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n};\ntype Loader = RawLoaderDefinitionFunction<LoaderOptions>;\n\nconst cache = new TransformCacheCollection();\n\nconst webpack5Loader: Loader = function webpack5LoaderPlugin(\n content,\n inputSourceMap\n) {\n function convertSourceMap(\n value: typeof inputSourceMap,\n filename: string\n ): RawSourceMap | undefined {\n if (typeof value === 'string' || !value) {\n return undefined;\n }\n\n return {\n ...value,\n file: value.file ?? filename,\n mappings: value.mappings ?? '',\n names: value.names ?? [],\n sources: value.sources ?? [],\n version: value.version ?? 3,\n };\n }\n\n // tell Webpack this loader is async\n this.async();\n\n logger('loader %s', this.resourcePath);\n\n const {\n sourceMap = undefined,\n preprocessor = undefined,\n extension = '.wyw-in-js.css',\n cacheProvider,\n ...rest\n } = this.getOptions() || {};\n\n const outputFileName = this.resourcePath.replace(/\\.[^.]+$/, extension);\n const resolveModule = this.getResolve({ dependencyType: 'esm' });\n\n const asyncResolve = (token: string, importer: string): Promise<string> => {\n const context = path.isAbsolute(importer)\n ? path.dirname(importer)\n : path.join(process.cwd(), path.dirname(importer));\n return new Promise((resolve, reject) => {\n resolveModule(context, token, (err, result) => {\n if (err) {\n reject(err);\n } else if (result) {\n this.addDependency(result);\n resolve(result);\n } else {\n reject(new Error(`Cannot resolve ${token}`));\n }\n });\n });\n };\n\n const transformServices = {\n options: {\n filename: this.resourcePath,\n inputSourceMap: convertSourceMap(inputSourceMap, this.resourcePath),\n root: process.cwd(),\n preprocessor,\n pluginOptions: rest,\n },\n cache,\n eventEmitter: sharedState.emitter,\n };\n\n transform(transformServices, content.toString(), asyncResolve)\n .then(\n async (result: Result) => {\n if (result.cssText) {\n let { cssText } = result;\n\n if (sourceMap) {\n cssText += `/*# sourceMappingURL=data:application/json;base64,${Buffer.from(\n result.cssSourceMapText || ''\n ).toString('base64')}*/`;\n }\n\n await Promise.all(\n result.dependencies?.map((dep) =>\n asyncResolve(dep, this.resourcePath)\n ) ?? []\n );\n\n try {\n const cacheInstance = await getCacheInstance(cacheProvider);\n\n await cacheInstance.set(this.resourcePath, cssText);\n\n await cacheInstance.setDependencies?.(\n this.resourcePath,\n this.getDependencies()\n );\n\n const request = `${outputFileName}!=!${outputCssLoader}?cacheProvider=${encodeURIComponent(\n typeof cacheProvider === 'string' ? cacheProvider : ''\n )}!${this.resourcePath}`;\n const stringifiedRequest = JSON.stringify(\n this.utils.contextify(this.context || this.rootContext, request)\n );\n\n this.callback(\n null,\n `${result.code}\\n\\nrequire(${stringifiedRequest});`,\n result.sourceMap ?? undefined\n );\n } catch (err) {\n this.callback(err as Error);\n }\n\n return;\n }\n\n this.callback(null, result.code, result.sourceMap ?? undefined);\n },\n (err: Error) => this.callback(err)\n )\n .catch((err: Error) => this.callback(err));\n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|
"name": "@wyw-in-js/webpack-loader",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@wyw-in-js/shared": "0.2.
|
|
6
|
-
"@wyw-in-js/transform": "0.2.
|
|
5
|
+
"@wyw-in-js/shared": "0.2.3",
|
|
6
|
+
"@wyw-in-js/transform": "0.2.3"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@types/node": "^16.18.55",
|
|
10
10
|
"source-map": "^0.7.4",
|
|
11
11
|
"webpack": "^5.76.0",
|
|
12
|
-
"@wyw-in-js/babel-config": "0.2.
|
|
13
|
-
"@wyw-in-js/eslint-config": "0.2.
|
|
14
|
-
"@wyw-in-js/jest-preset": "0.2.
|
|
15
|
-
"@wyw-in-js/ts-config": "0.2.
|
|
12
|
+
"@wyw-in-js/babel-config": "0.2.3",
|
|
13
|
+
"@wyw-in-js/eslint-config": "0.2.3",
|
|
14
|
+
"@wyw-in-js/jest-preset": "0.2.3",
|
|
15
|
+
"@wyw-in-js/ts-config": "0.2.3"
|
|
16
16
|
},
|
|
17
17
|
"engines": {
|
|
18
18
|
"node": ">=16.0.0"
|
package/types/index.d.ts
CHANGED
|
@@ -7,11 +7,12 @@ import type { RawLoaderDefinitionFunction } from 'webpack';
|
|
|
7
7
|
import type { Preprocessor } from '@wyw-in-js/transform';
|
|
8
8
|
import type { ICache } from './cache';
|
|
9
9
|
export { WYWinJSDebugPlugin } from './WYWinJSDebugPlugin';
|
|
10
|
-
type
|
|
10
|
+
export type LoaderOptions = {
|
|
11
11
|
cacheProvider?: string | ICache;
|
|
12
12
|
extension?: string;
|
|
13
13
|
preprocessor?: Preprocessor;
|
|
14
14
|
sourceMap?: boolean;
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
|
+
type Loader = RawLoaderDefinitionFunction<LoaderOptions>;
|
|
16
17
|
declare const webpack5Loader: Loader;
|
|
17
18
|
export default webpack5Loader;
|