Skip to content

Commit

Permalink
fix: remove patches that support to omit '.vue' suffix (#68)
Browse files Browse the repository at this point in the history
* fix: remove patches that support to omit '.vue' suffix

* test: no need to test vite patch
  • Loading branch information
Chieffo2021 committed Aug 26, 2021
1 parent 18cc9ec commit fab25f0
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 72 deletions.
5 changes: 3 additions & 2 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ webpack-to-vite -d <project path>
* 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 支持
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"webpack-to-vite": "dist/bin/index.js"
},
"files": [
"dist",
"patches"
"dist"
],
"scripts": {
"prebuild": "del-cli dist/",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
32 changes: 0 additions & 32 deletions patches/vite+2.4.4.patch

This file was deleted.

7 changes: 1 addition & 6 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -64,10 +63,6 @@ export async function start (config: Config): Promise<void> {
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'
Expand Down
3 changes: 1 addition & 2 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
6 changes: 0 additions & 6 deletions src/generate/genePackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions src/generate/genePatches.ts

This file was deleted.

2 changes: 0 additions & 2 deletions tests/genePackageJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}))
});

Expand Down

0 comments on commit fab25f0

Please sign in to comment.