diff --git a/README-zh.md b/README-zh.md index b5ee668..4dae220 100644 --- a/README-zh.md +++ b/README-zh.md @@ -65,9 +65,10 @@ webpack-to-vite -d * Vue2 项目需要的插件:`vite-plugin-vue2`,默认通过 `{ jsx: true }` 选项启用 `jsx` 支持 * Vue3 项目需要的插件:`@vitejs/plugin-vue`, `@vitejs/plugin-vue-jsx` * ✅ B05: 支持省略 `.vue` 扩展名的导入 - * 在 `vite.config.js` 中,设置 `resolve.extensions` 配置项为 `['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']`, + * ~~在 `vite.config.js` 中,设置 `resolve.extensions` 配置项为 `['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']`, 然后您可能会遇到 "[Problems caused by using alisaes and omitting file suffixes at the same time](https://github.com/vitejs/vite/issues/3532)" 这样的问题, - 我们使用补丁来解决这个问题,在 vite 接受相关 PR 之前 + 我们使用补丁来解决这个问题,在 vite 接受相关 PR 之前~~ + 自从 vite 发布 `^2.5.0` 版本后已修复 * ✅ B06: sass 支持 * 如果项目使用到 `node-sass` 依赖,则转换为 `sass` 依赖 * ✅ B07: postcss 8 支持 diff --git a/README.md b/README.md index 305b787..68cc319 100644 --- a/README.md +++ b/README.md @@ -65,9 +65,10 @@ Legend of annotations: * necessary for Vue2: `vite-plugin-vue2`, we set `{ jsx: true }` option to enable `jsx` support by default * necessary for Vue3: `@vitejs/plugin-vue`, `@vitejs/plugin-vue-jsx` * ✅ B05: imports that omit `.vue` extension is supported - * If the `resolve.extensions` is set to be `['.mjs','.js','.ts','.jsx','.tsx','.json ','.vue']`, in `vite.config.js`, + * ~~If the `resolve.extensions` is set to be `['.mjs','.js','.ts','.jsx','.tsx','.json ','.vue']`, in `vite.config.js`, then you may encounter errors like '[Problems caused by using alisaes and omitting file suffixes at the same time](https://github.com/vitejs/vite/issues/3532)'. - We use a patch to fix this issue, in case of vite didn't accept relate PR + We use a patch to fix this issue, in case of vite didn't accept relate PR~~ + fixed since vite released version `^2.5.0` * ✅ B06: `sass` is supported * if `node-sass` is used in dependency, then we'll convert it to `sass` to dependencies * ✅ B07: `postcss 8` is supported diff --git a/package.json b/package.json index e6e17bc..0f1710a 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,7 @@ "webpack-to-vite": "dist/bin/index.js" }, "files": [ - "dist", - "patches" + "dist" ], "scripts": { "prebuild": "del-cli dist/", @@ -51,11 +50,10 @@ "eslint-plugin-promise": "^5.1.0", "jest": "^27.0.4", "lint-staged": "^11.0.0", - "postinstall-postinstall": "^2.1.0", "prettier": "^2.3.1", "ts-jest": "^27.0.3", "typescript": "^4.3.2", - "vite": "2.4.4", + "vite": "^2.5.1", "vite-plugin-env-compatible": "^1.0.0", "vite-plugin-vue2": "^1.6.2", "vue-loader": "^15.9.7", @@ -70,7 +68,6 @@ "ejs": "^3.1.6", "globby": "^11.0.3", "jscodeshift": "^0.12.0", - "patch-package": "^6.4.7", "semver": "^7.3.5", "table": "^6.7.1", "vue-eslint-parser": "^7.6.0", diff --git a/patches/vite+2.4.4.patch b/patches/vite+2.4.4.patch deleted file mode 100644 index 75b8644..0000000 --- a/patches/vite+2.4.4.patch +++ /dev/null @@ -1,32 +0,0 @@ -diff --git a/node_modules/vite/dist/node/chunks/dep-c1a9de64.js b/node_modules/vite/dist/node/chunks/dep-c1a9de64.js -index 9f04e5f..eb05504 100644 ---- a/node_modules/vite/dist/node/chunks/dep-c1a9de64.js -+++ b/node_modules/vite/dist/node/chunks/dep-c1a9de64.js -@@ -51192,8 +51192,10 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) { - } - else { - // linked package, keep crawling -+ const namespace = htmlTypesRE.test(resolved) ? 'html' : undefined - return { -- path: path__default.resolve(resolved) -+ path: path__default.resolve(resolved), -+ namespace - }; - } - } -diff --git a/node_modules/vite/src/node/optimizer/scan.ts b/node_modules/vite/src/node/optimizer/scan.ts -index 9193116..ed9ce51 100644 ---- a/node_modules/vite/src/node/optimizer/scan.ts -+++ b/node_modules/vite/src/node/optimizer/scan.ts -@@ -283,8 +283,10 @@ function esbuildScanPlugin( - return externalUnlessEntry({ path: id }) - } else { - // linked package, keep crawling -+ const namespace = htmlTypesRE.test(resolved) ? 'html' : undefined - return { -- path: path.resolve(resolved) -+ path: path.resolve(resolved), -+ namespace - } - } - } else { diff --git a/src/cli/cli.ts b/src/cli/cli.ts index d5e63b3..48860f5 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -4,11 +4,10 @@ import chalk from 'chalk' import { geneIndexHtml } from '../generate/geneIndexHtml' import { genePackageJson } from '../generate/genePackageJson' import { geneViteConfig } from '../generate/geneViteConfig' -import { genePatches } from '../generate/genePatches' import { Command } from 'commander' import { Config } from '../config/config' import { astParseRoot, AstParsingResult } from '../ast-parse/astParse' -import { printReport, recordConver } from '../utils/report' +import { printReport } from '../utils/report' import cliProgress from 'cli-progress' const cliInstance = new cliProgress.SingleBar({ @@ -64,10 +63,6 @@ export async function start (config: Config): Promise { await geneIndexHtml(rootDir, config, astParsingResult) printReport(config.rootDir, beginTime) // output conversion - // generate patches - const patchesDir = path.resolve(rootDir, 'patches') - genePatches(patchesDir) - recordConver({ num: 'B05', feat: 'required plugins' }) console.log(chalk.green('************************ Done ! ************************')) const pkgManager = fs.existsSync(path.resolve(rootDir, 'yarn.lock')) ? 'yarn' diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 8e6cbd7..e70e85d 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -1,6 +1,6 @@ export const DEFAULT_VUE_VERSION = undefined export const VUE_COMPILER_SFC_VERSION = '^3.0.5' -export const VITE_VERSION = '2.4.4' +export const VITE_VERSION = '^2.5.1' export const VITE_PLUGIN_VUE_VERSION = '^1.2.1' export const VITE_PLUGIN_VUE_JSX_VERSION = '^1.1.5' export const VITE_PLUGIN_VUE_TWO_VERSION = '^1.5.1' @@ -10,4 +10,3 @@ export const SASS_VERSION = '^1.34.0' export const VITE_PLUGIN_COMMONJS_VERSION = '^1.0.0-beta3' export const VITE_PLUGIN_REQUIRE_CONTEXT_VERSION = '1.0.6' export const POSTCSS_VERSION = '^8.3.5' -export const PATCH_PACKAGE_VERSION = '^6.4.7' diff --git a/src/generate/genePackageJson.ts b/src/generate/genePackageJson.ts index fac14e5..f32caab 100644 --- a/src/generate/genePackageJson.ts +++ b/src/generate/genePackageJson.ts @@ -51,16 +51,10 @@ export function genePackageJson (packageJsonPath: string, astParsingResult?: Ast packageJson.devDependencies.postcss = constants.POSTCSS_VERSION } - // patch-package support - packageJson.devDependencies['patch-package'] = constants.PATCH_PACKAGE_VERSION - // add vite dev script packageJson.scripts['serve-vite'] = 'vite' packageJson.scripts['build-vite'] = 'vite build' - // add postinatall - packageJson.scripts.postinstall = 'patch-package' - let result = processDependencies(originPackageJson.dependencies, packageJson.dependencies, packageJson.devDependencies) packageJson.dependencies = result.targetDependencies packageJson.devDependencies = result.restDependencies diff --git a/src/generate/genePatches.ts b/src/generate/genePatches.ts deleted file mode 100644 index f319cbf..0000000 --- a/src/generate/genePatches.ts +++ /dev/null @@ -1,15 +0,0 @@ -import fs from 'fs' -import path from 'path' -import { readSync, writeSync } from '../utils/file' - -export function genePatches (patchesDir: string): void { - const copyFromPatchesDir: string = path.resolve(__dirname, '../../../patches') - // read all patches name - const patchesInfo = fs.readdirSync(copyFromPatchesDir); - // inject patch - patchesInfo.forEach(patch => { - const filePath = path.resolve(patchesDir, patch); - const patchContent = readSync(path.resolve(copyFromPatchesDir, patch)); - writeSync(filePath, patchContent); - }); -} diff --git a/tests/genePackageJson.test.ts b/tests/genePackageJson.test.ts index 3efa930..1cad6be 100644 --- a/tests/genePackageJson.test.ts +++ b/tests/genePackageJson.test.ts @@ -29,12 +29,10 @@ describe('genePackageJson', () => { 'vite': expect.any(String), 'sass': expect.any(String), 'postcss': expect.any(String), - 'patch-package': expect.any(String), })) expect(packageJsonContent.scripts).toMatchObject(expect.objectContaining({ 'serve-vite': 'vite', 'build-vite': 'vite build', - 'postinstall': 'patch-package', })) });