diff --git a/package.json b/package.json index 09f1844ff6be..0f36f6a4d5db 100644 --- a/package.json +++ b/package.json @@ -197,7 +197,6 @@ "vue-template-compiler": "^2.6.11", "webpack": "5.69.0", "webpack-chain": "6.5.1", - "webpack-dev-server": "4.7.4", - "webpack-sources": "^3.2.3" + "webpack-dev-server": "4.7.4" } } diff --git a/packages/taro-webpack5-prebundle/package.json b/packages/taro-webpack5-prebundle/package.json index 88b87e2fed0f..db4df7ca14a8 100644 --- a/packages/taro-webpack5-prebundle/package.json +++ b/packages/taro-webpack5-prebundle/package.json @@ -38,7 +38,6 @@ "fs-extra": "^8.0.1", "lodash": "^4.17.21", "webpack-chain": "6.5.1", - "webpack-sources": "^3.2.3", "webpack-virtual-modules": "^0.4.3" }, "devDependencies": { diff --git a/packages/taro-webpack5-prebundle/src/utils/webpack.ts b/packages/taro-webpack5-prebundle/src/utils/webpack.ts index e775d5673807..880af5d614f4 100644 --- a/packages/taro-webpack5-prebundle/src/utils/webpack.ts +++ b/packages/taro-webpack5-prebundle/src/utils/webpack.ts @@ -1,12 +1,13 @@ import { promoteRelativePath } from '@tarojs/helper' import path from 'path' -import { Chunk, Compilation } from 'webpack' -import { ConcatSource, Source } from 'webpack-sources' +import { Chunk, Compilation, sources } from 'webpack' + +const { ConcatSource } = sources /** * 在文本头部加入一些 require 语句 */ -export function addRequireToSource (id: string, modules: Source, commonChunks: (Chunk | { name: string })[]) { +export function addRequireToSource (id: string, modules: sources.Source, commonChunks: (Chunk | { name: string })[]) { const source = new ConcatSource() commonChunks.forEach(chunkItem => { source.add(`require(${JSON.stringify(promoteRelativePath(path.relative(id, chunkItem.name)))});\n`) diff --git a/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModule.ts b/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModule.ts index e060c2da4d9e..f1a5267faf0c 100644 --- a/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModule.ts +++ b/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModule.ts @@ -3,9 +3,10 @@ * MIT License http://www.opensource.org/licenses/mit-license.php * Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy, Marais Rossouw @maraisr */ -import webpack from 'webpack' +import webpack, { sources } from 'webpack' import ContainerPlugin from 'webpack/lib/container/ContainerPlugin' -import { ConcatSource } from 'webpack-sources' + +const { ConcatSource } = sources const { Template, RuntimeGlobals } = webpack const ContainerEntryModule = require('webpack/lib/container/ContainerEntryModule') diff --git a/packages/taro-webpack5-prebundle/src/webpack/TaroContainerReferencePlugin.ts b/packages/taro-webpack5-prebundle/src/webpack/TaroContainerReferencePlugin.ts index 76d2a3099c3d..b85fb3cda4c6 100644 --- a/packages/taro-webpack5-prebundle/src/webpack/TaroContainerReferencePlugin.ts +++ b/packages/taro-webpack5-prebundle/src/webpack/TaroContainerReferencePlugin.ts @@ -4,11 +4,10 @@ * Author Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy */ import { META_TYPE } from '@tarojs/helper' -import webpack, { Compiler, NormalModule, RuntimeGlobals } from 'webpack' +import webpack, { Compiler, NormalModule, RuntimeGlobals, sources } from 'webpack' import ContainerReferencePlugin from 'webpack/lib/container/ContainerReferencePlugin' import RemoteModule from 'webpack/lib/container/RemoteModule' import type { ContainerReferencePluginOptions, RemotesConfig } from 'webpack/types' -import { ConcatSource, RawSource } from 'webpack-sources' import { addRequireToSource, getChunkEntryModule, getChunkIdOrName } from '../utils' import { CollectedDeps, MF_NAME } from '../utils/constant' @@ -23,6 +22,8 @@ const RemoteToExternalDependency = require('webpack/lib/container/RemoteToExtern const PLUGIN_NAME = 'TaroContainerReferencePlugin' const slashCode = '/'.charCodeAt(0) +const { RawSource } = sources + type MFOptions = Partial interface IParams { @@ -191,7 +192,7 @@ export default class TaroContainerReferencePlugin extends ContainerReferencePlug const hooks = webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation) hooks.render.tap( PLUGIN_NAME, - (modules: ConcatSource, { chunk }) => { + (modules: sources.ConcatSource, { chunk }) => { const chunkEntryModule = getChunkEntryModule(compilation, chunk) as any if (chunkEntryModule) { const entryModule = chunkEntryModule.rootModule ?? chunkEntryModule diff --git a/packages/taro-webpack5-runner/package.json b/packages/taro-webpack5-runner/package.json index 55ed9454b91c..22ea17c8ec30 100644 --- a/packages/taro-webpack5-runner/package.json +++ b/packages/taro-webpack5-runner/package.json @@ -95,7 +95,6 @@ "webpack-chain": "6.5.1", "webpack-dev-server": "4.7.4", "webpack-format-messages": "^2.0.6", - "webpack-sources": "^3.2.3", "webpackbar": "^5.0.2" }, "devDependencies": { diff --git a/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts b/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts index 4c3af4c214a9..bac6697c76c0 100644 --- a/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts +++ b/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts @@ -17,9 +17,8 @@ import { AppConfig, Config } from '@tarojs/taro' import fs from 'fs-extra' import { urlToRequest } from 'loader-utils' import path from 'path' -import webpack, { Compilation, Compiler } from 'webpack' +import webpack, { Compilation, Compiler, sources } from 'webpack' import EntryDependency from 'webpack/lib/dependencies/EntryDependency' -import { ConcatSource, RawSource } from 'webpack-sources' import TaroSingleEntryDependency from '../dependencies/TaroSingleEntryDependency' import { PrerenderConfig, validatePrerenderPages } from '../prerender/prerender' @@ -30,6 +29,7 @@ import TaroNormalModulesPlugin from './TaroNormalModulesPlugin' import TaroSingleEntryPlugin from './TaroSingleEntryPlugin' const PLUGIN_NAME = 'TaroMiniPlugin' +const { ConcatSource, RawSource } = sources interface ITaroMiniPluginOptions { appEntry?: string diff --git a/packages/taro-webpack5-runner/src/plugins/MiniSplitChunksPlugin.ts b/packages/taro-webpack5-runner/src/plugins/MiniSplitChunksPlugin.ts index bd5f1f85ec25..e74692bb7e8a 100644 --- a/packages/taro-webpack5-runner/src/plugins/MiniSplitChunksPlugin.ts +++ b/packages/taro-webpack5-runner/src/plugins/MiniSplitChunksPlugin.ts @@ -5,13 +5,13 @@ import md5 from 'md5' import path from 'path' import { Chunk, ChunkGraph, Compilation, Compiler, Module, sources } from 'webpack' import SplitChunksPlugin from 'webpack/lib/optimize/SplitChunksPlugin' -import { ConcatSource, RawSource } from 'webpack-sources' import type { IFileType } from '../utils/types' const PLUGIN_NAME = 'MiniSplitChunkPlugin' // 插件名 const SUB_COMMON_DIR = 'sub-common' // 分包公共依赖目录 const SUB_VENDORS_NAME = 'sub-vendors' // 分包 vendors 文件名 +const { ConcatSource, RawSource } = sources const FileExtsMap = { JS: '.js', diff --git a/packages/taro-webpack5-runner/src/plugins/TaroLoadChunksPlugin.ts b/packages/taro-webpack5-runner/src/plugins/TaroLoadChunksPlugin.ts index 69c48314c7ea..82df4aad5f45 100644 --- a/packages/taro-webpack5-runner/src/plugins/TaroLoadChunksPlugin.ts +++ b/packages/taro-webpack5-runner/src/plugins/TaroLoadChunksPlugin.ts @@ -3,8 +3,7 @@ import { taroJsComponents } from '@tarojs/helper' import { toDashed } from '@tarojs/shared' -import webpack, { Chunk, ChunkGraph, Compilation, Compiler } from 'webpack' -import { ConcatSource } from 'webpack-sources' +import webpack, { Chunk, ChunkGraph, Compilation, Compiler, sources } from 'webpack' import { componentConfig } from '../template/component' import type { AddPageChunks, IComponent } from '../utils/types' @@ -12,6 +11,7 @@ import { addRequireToSource, getChunkEntryModule, getChunkIdOrName } from '../ut import TaroNormalModule from './TaroNormalModule' const PLUGIN_NAME = 'TaroLoadChunksPlugin' +const { ConcatSource } = sources interface IOptions { commonChunks: string[] @@ -88,7 +88,7 @@ export default class TaroLoadChunksPlugin { } }) - webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).render.tap(PLUGIN_NAME, (modules: ConcatSource, { chunk }) => { + webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).render.tap(PLUGIN_NAME, (modules: sources.ConcatSource, { chunk }) => { const chunkEntryModule = getChunkEntryModule(compilation, chunk) as any if (chunkEntryModule) { const entryModule: TaroNormalModule = chunkEntryModule.rootModule ?? chunkEntryModule @@ -108,7 +108,7 @@ export default class TaroLoadChunksPlugin { /** * 在每个 chunk 文本刚生成后,按判断条件在文本头部插入 require 语句 */ - webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).render.tap(PLUGIN_NAME, (modules: ConcatSource, { chunk }) => { + webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).render.tap(PLUGIN_NAME, (modules: sources.ConcatSource, { chunk }) => { const chunkEntryModule = getChunkEntryModule(compilation, chunk) as any if (chunkEntryModule) { if (this.isBuildPlugin) { diff --git a/packages/taro-webpack5-runner/src/utils/webpack.ts b/packages/taro-webpack5-runner/src/utils/webpack.ts index e775d5673807..3098062aa1de 100644 --- a/packages/taro-webpack5-runner/src/utils/webpack.ts +++ b/packages/taro-webpack5-runner/src/utils/webpack.ts @@ -1,12 +1,13 @@ import { promoteRelativePath } from '@tarojs/helper' import path from 'path' -import { Chunk, Compilation } from 'webpack' -import { ConcatSource, Source } from 'webpack-sources' +import { Chunk, Compilation, sources} from 'webpack' + +const { ConcatSource } = sources /** * 在文本头部加入一些 require 语句 */ -export function addRequireToSource (id: string, modules: Source, commonChunks: (Chunk | { name: string })[]) { +export function addRequireToSource (id: string, modules: sources.Source, commonChunks: (Chunk | { name: string })[]) { const source = new ConcatSource() commonChunks.forEach(chunkItem => { source.add(`require(${JSON.stringify(promoteRelativePath(path.relative(id, chunkItem.name)))});\n`) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ba85c5cc1e0b..8f8abca72765 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,9 +56,9 @@ importers: '@testing-library/jest-native': ^4.0.4 '@testing-library/react-native': ^11.0.0 '@types/autoprefixer': 9.7.0 + '@types/babel-types': ^7.0.7 '@types/babel__core': ^7.1.14 '@types/babel__traverse': ^7.0.7 - '@types/babel-types': ^7.0.7 '@types/debug': ^4.1.5 '@types/detect-port': 1.3.0 '@types/fs-extra': ^8.0.1 @@ -160,7 +160,6 @@ importers: webpack: 5.69.0 webpack-chain: 6.5.1 webpack-dev-server: 4.7.4 - webpack-sources: ^3.2.3 devDependencies: '@babel/cli': registry.npmjs.org/@babel/cli/7.17.10_@babel+core@7.18.5 '@babel/core': registry.npmjs.org/@babel/core/7.18.5 @@ -214,9 +213,9 @@ importers: '@testing-library/jest-native': registry.npmjs.org/@testing-library/jest-native/4.0.5 '@testing-library/react-native': registry.npmjs.org/@testing-library/react-native/11.0.0_hu3ahtgtujq76vsul4i4hbebdu '@types/autoprefixer': registry.npmjs.org/@types/autoprefixer/9.7.0 + '@types/babel-types': registry.npmjs.org/@types/babel-types/7.0.11 '@types/babel__core': registry.npmjs.org/@types/babel__core/7.1.19 '@types/babel__traverse': registry.npmjs.org/@types/babel__traverse/7.17.1 - '@types/babel-types': registry.npmjs.org/@types/babel-types/7.0.11 '@types/debug': registry.npmjs.org/@types/debug/4.1.7 '@types/detect-port': registry.npmjs.org/@types/detect-port/1.3.0 '@types/fs-extra': registry.npmjs.org/@types/fs-extra/8.1.2 @@ -318,7 +317,6 @@ importers: webpack: registry.npmjs.org/webpack/5.69.0_esbuild@0.14.47 webpack-chain: registry.npmjs.org/webpack-chain/6.5.1 webpack-dev-server: registry.npmjs.org/webpack-dev-server/4.7.4_webpack@5.69.0 - webpack-sources: registry.npmjs.org/webpack-sources/3.2.3 packages/babel-plugin-transform-react-jsx-to-rn-stylesheet: specifiers: @@ -1455,7 +1453,6 @@ importers: lodash: ^4.17.21 webpack-chain: 6.5.1 webpack-dev-server: 4.7.4 - webpack-sources: ^3.2.3 webpack-virtual-modules: ^0.4.3 dependencies: '@swc/core': registry.npmjs.org/@swc/core/1.2.205 @@ -1467,7 +1464,6 @@ importers: fs-extra: registry.npmjs.org/fs-extra/8.1.0 lodash: registry.npmjs.org/lodash/4.17.21 webpack-chain: registry.npmjs.org/webpack-chain/6.5.1 - webpack-sources: registry.npmjs.org/webpack-sources/3.2.3 webpack-virtual-modules: registry.npmjs.org/webpack-virtual-modules/0.4.4 devDependencies: webpack-dev-server: registry.npmjs.org/webpack-dev-server/4.7.4 @@ -1538,7 +1534,6 @@ importers: webpack-chain: 6.5.1 webpack-dev-server: 4.7.4 webpack-format-messages: ^2.0.6 - webpack-sources: ^3.2.3 webpackbar: ^5.0.2 dependencies: '@parcel/css': registry.npmjs.org/@parcel/css/1.10.1 @@ -1603,7 +1598,6 @@ importers: webpack-chain: registry.npmjs.org/webpack-chain/6.5.1 webpack-dev-server: registry.npmjs.org/webpack-dev-server/4.7.4_webpack@5.69.0 webpack-format-messages: registry.npmjs.org/webpack-format-messages/2.0.6 - webpack-sources: registry.npmjs.org/webpack-sources/3.2.3 webpackbar: registry.npmjs.org/webpackbar/5.0.2_webpack@5.69.0 devDependencies: '@babel/core': registry.npmjs.org/@babel/core/7.18.5 @@ -13765,7 +13759,7 @@ packages: mississippi: registry.npmjs.org/mississippi/3.0.0 mkdirp: registry.npmjs.org/mkdirp/0.5.6 move-concurrently: registry.npmjs.org/move-concurrently/1.0.1 - promise-inflight: registry.npmjs.org/promise-inflight/1.0.1_bluebird@3.7.2 + promise-inflight: registry.npmjs.org/promise-inflight/1.0.1 rimraf: registry.npmjs.org/rimraf/2.7.1 ssri: registry.npmjs.org/ssri/6.0.2 unique-filename: registry.npmjs.org/unique-filename/1.1.1 @@ -15323,8 +15317,8 @@ packages: engines: {node: '>=10'} hasBin: true dependencies: - is-text-path: registry.npmjs.org/is-text-path/1.0.1 JSONStream: registry.npmjs.org/JSONStream/1.3.5 + is-text-path: registry.npmjs.org/is-text-path/1.0.1 lodash: registry.npmjs.org/lodash/4.17.21 meow: registry.npmjs.org/meow/8.1.2 split2: registry.npmjs.org/split2/3.2.2 @@ -30071,19 +30065,6 @@ packages: bluebird: optional: true - registry.npmjs.org/promise-inflight/1.0.1_bluebird@3.7.2: - resolution: {integrity: sha512-6zWPyEOFaQBJYcGMHBKTKJ3u6TBsnMFOIZSa6ce1e/ZrrsOlnHRHbabMjLiBYKp+n44X9eUI6VUPaukCXHuG4g==, registry: https://registry.yarnpkg.com/, tarball: https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz} - id: registry.npmjs.org/promise-inflight/1.0.1 - name: promise-inflight - version: 1.0.1 - peerDependencies: - bluebird: '*' - peerDependenciesMeta: - bluebird: - optional: true - dependencies: - bluebird: registry.npmjs.org/bluebird/3.7.2 - registry.npmjs.org/promise-polyfill/7.1.2: resolution: {integrity: sha512-FuEc12/eKqqoRYIGBrUptCBRhobL19PS2U31vMNTfyck1FxPyMfgsXyW4Mav85y/ZN1hop3hOwRlUDok23oYfQ==, registry: https://registry.yarnpkg.com/, tarball: https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-7.1.2.tgz} name: promise-polyfill diff --git a/types/webpack-sources.d.ts b/types/webpack-sources.d.ts deleted file mode 100644 index 31ff32b0d98b..000000000000 --- a/types/webpack-sources.d.ts +++ /dev/null @@ -1,133 +0,0 @@ -/* -https://github.com/webpack/webpack/blob/main/declarations.d.ts - -Copyright JS Foundation and other contributors - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -'Software'), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -**/ - -declare module "webpack-sources" { - export type MapOptions = { columns?: boolean; module?: boolean }; - - export abstract class Source { - size(): number; - - map(options?: MapOptions): Object; - - sourceAndMap(options?: MapOptions): { - source: string | Buffer; - map: Object; - }; - - updateHash(hash: any): void; - - source(): string | Buffer; - - buffer(): Buffer; - } - - export class RawSource extends Source { - constructor(source: string | Buffer, convertToString?: boolean); - - isBuffer(): boolean; - } - - export class OriginalSource extends Source { - constructor(source: string | Buffer, name: string); - - getName(): string; - } - - export class ReplaceSource extends Source { - constructor(source: Source, name?: string); - - replace(start: number, end: number, newValue: string, name?: string): void; - insert(pos: number, newValue: string, name?: string): void; - - getName(): string; - original(): string; - getReplacements(): { - start: number; - end: number; - content: string; - insertIndex: number; - name: string; - }[]; - } - - export class SourceMapSource extends Source { - constructor( - source: string | Buffer, - name: string, - sourceMap: Object | string | Buffer, - originalSource?: string | Buffer, - innerSourceMap?: Object | string | Buffer, - removeOriginalSource?: boolean - ); - - getArgsAsBuffers(): [ - Buffer, - string, - Buffer, - Buffer | undefined, - Buffer | undefined, - boolean - ]; - } - - export class ConcatSource extends Source { - constructor(...args: (string | Source)[]); - - getChildren(): Source[]; - - add(item: string | Source): void; - addAllSkipOptimizing(items: Source[]): void; - } - - export class PrefixSource extends Source { - constructor(prefix: string, source: string | Source); - - original(): Source; - getPrefix(): string; - } - - export class CachedSource extends Source { - constructor(source: Source); - constructor(source: Source | (() => Source), cachedData?: any); - - original(): Source; - originalLazy(): Source | (() => Source); - getCachedData(): any; - } - - export class SizeOnlySource extends Source { - constructor(size: number); - } - - interface SourceLike { - source(): string | Buffer; - } - - export class CompatSource extends Source { - constructor(sourceLike: SourceLike); - - static from(sourceLike: SourceLike): Source; - } -}