diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 1d0029c531..66d44970a9 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -26,6 +26,7 @@ yarn # if you have the old vue-cli installed globally, you may # need to uninstall it first. cd packages/@vue/cli +# before yarn link, you can delete the link in `~/.config/yarn/link/@vue` (see issue: [yarn link error message is not helpful](https://github.com/yarnpkg/yarn/issues/7054)) yarn link # create test projects in /packages/test diff --git a/CHANGELOG.md b/CHANGELOG.md index f2feb80979..8ba32042a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,27 @@ +## 4.5.7 (2020-10-07) + +#### :bug: Bug Fix +* `@vue/cli-plugin-babel`, `@vue/cli-plugin-typescript`, `@vue/cli-service` + * [#5903](https://github.com/vuejs/vue-cli/pull/5903) fix: update the `.vue` file shim for Vue 3 ([@sodatea](https://github.com/sodatea)) +* `@vue/cli` + * [#5871](https://github.com/vuejs/vue-cli/pull/5871) fix: more accurate warning message for missing global peer dependencies ([@sodatea](https://github.com/sodatea)) + * [#5902](https://github.com/vuejs/vue-cli/pull/5902) fix: incorrectly read Taobao binary mirror configuration. ([@godky](https://github.com/godky)) + * [#5892](https://github.com/vuejs/vue-cli/pull/5892) fix: respect scope when resolving package metadata ([@bodograumann](https://github.com/bodograumann)) +* `@vue/cli-plugin-pwa`, `@vue/cli-service` + * [#5899](https://github.com/vuejs/vue-cli/pull/5899) fix: shouldn't remove attribute quotes in HTML ([@sodatea](https://github.com/sodatea)) + +#### :memo: Documentation +* [#5835](https://github.com/vuejs/vue-cli/pull/5835) Update Vercel deployment instructions ([@timothyis](https://github.com/timothyis)) + +#### Committers: 4 +- Bodo Graumann ([@bodograumann](https://github.com/bodograumann)) +- Haoqun Jiang ([@sodatea](https://github.com/sodatea)) +- Timothy ([@timothyis](https://github.com/timothyis)) +- kzhang ([@godky](https://github.com/godky)) + + + ## 4.5.6 (2020-09-10) #### :bug: Bug Fix diff --git a/docs/guide/deployment.md b/docs/guide/deployment.md index c5b4108f2c..c39d8980ef 100644 --- a/docs/guide/deployment.md +++ b/docs/guide/deployment.md @@ -145,7 +145,7 @@ Typically, your static website will be hosted on https://yourUserName.gitlab.io/ ```javascript -// vue.config.js file to be place in the root of your repository +// vue.config.js file to be placed in the root of your repository module.exports = { publicPath: process.env.NODE_ENV === 'production' @@ -178,6 +178,21 @@ In order to receive direct hits using `history mode` on Vue Router, you need to More information on [Netlify redirects documentation](https://www.netlify.com/docs/redirects/#history-pushstate-and-single-page-apps). +If you are using [@vue/cli-plugin-pwa](https://cli.vuejs.org/core-plugins/pwa.html#vue-cli-plugin-pwa) make sure to exclude the `_redirects` file from being cached by the service worker. +To do so, add the following to your `vue.config.js`: +```javascript +// vue.config.js file to be placed in the root of your repository + +module.exports = { + pwa: { + workboxOptions: { + exclude: [/_redirects/] + } + } +} +``` +Checkout [workboxOptions](https://cli.vuejs.org/core-plugins/pwa.html#configuration) and [exclude](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-webpack-plugin.InjectManifest#InjectManifest) for more. + ### Render [Render](https://render.com) offers [free static site hosting](https://render.com/docs/static-sites) with fully managed SSL, a global CDN and continuous auto deploys from GitHub. @@ -269,77 +284,38 @@ Please refer to the [Firebase Documentation](https://firebase.google.com/docs/ho ### Vercel -This example uses the latest Vercel platform version 2. +[Vercel](https://vercel.com/home) is a cloud platform that enables developers to host Jamstack websites and web services that deploy instantly, scale automatically, and requires no supervision, all with zero configuration. They provide a global edge network, SSL encryption, asset compression, cache invalidation, and more. -1. Install the Vercel CLI: +#### Step 1: Deploying your Vue project to Vercel -```bash -npm install -g vercel +To deploy your Vue project with a [Vercel for Git Integration](https://vercel.com/docs/git-integrations), make sure it has been pushed to a Git repository. -# Or, if you prefer a local one -npm install vercel -``` +Import the project into Vercel using the [Import Flow](https://vercel.com/import/git). During the import, you will find all relevant [options](https://vercel.com/docs/build-step#build-&-development-settings) preconfigured for you with the ability to change as needed. -2. Add a `vercel.json` file to your project root: +After your project has been imported, all subsequent pushes to branches will generate [Preview Deployments](https://vercel.com/docs/platform/deployments#preview), and all changes made to the [Production Branch](https://vercel.com/docs/git-integrations#production-branch) (commonly "master" or "main") will result in a [Production Deployment](https://vercel.com/docs/platform/deployments#production). - ```json - { - "name": "my-example-app", - "version": 2, - "builds": [ - { - "src": "package.json", - "use": "@vercel/static-build" - } - ], - "routes": [ - { - "src": "/(js|css|img)/.*", - "headers": { "cache-control": "max-age=31536000, immutable" } - }, - { "handle": "filesystem" }, - { "src": ".*", "dest": "/" } - ], - "alias": "example.com" - } - ``` +Once deployed, you will get a URL to see your app live, such as the following: https://vue-example-tawny.vercel.app/. - If you have different/additional folders, modify the route accordingly: - - ```diff - - { - - "src": "/(js|css|img)/.*", - - "headers": { "cache-control": "max-age=31536000, immutable" } - - } - + { - + "src": "/(js|css|img|fonts|media)/.*", - + "headers": { "cache-control": "max-age=31536000, immutable" } - + } - ``` +#### Step 2 (optional): Using a Custom Domain - If your `outputDir` is not the default `dist`, say `build`: - - ```diff - - { - - "src": "package.json", - - "use": "@vercel/static-build" - - } - + { - + "src": "package.json", - + "use": "@vercel/static-build", - + "config": { "distDir": "build" } - + } - ``` +If you want to use a Custom Domain with your Vercel deployment, you can **Add** or **Transfer in** your domain via your Vercel [account Domain settings.](https://vercel.com/dashboard/domains) -3. Adding a `now-build` script in `package.json`: +To add your domain to your project, navigate to your [Project](https://vercel.com/docs/platform/projects) from the Vercel Dashboard. Once you have selected your project, click on the "Settings" tab, then select the **Domains** menu item. From your projects **Domain** page, enter the domain you wish to add to your project. - ```json - "vercel-build": "npm run build" - ``` +Once the domain as been added, you will be presented with different methods for configuring it. + +#### Deploying a fresh Vue project + +You can deploy a fresh Vue project, with a Git repository set up for you, with the following Deploy Button: + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/git?s=https%3A%2F%2Fgithub.com%2Fvercel%2Fvercel%2Ftree%2Fmaster%2Fexamples%2Fvue) - To make a deployment, run `vercel`. +## References: - If you want your deployment aliased, run `vercel --target production` instead. +- [Example Source](https://github.com/vercel/vercel/tree/master/examples/vue) +- [Official Vercel Guide](https://vercel.com/guides/deploying-vuejs-to-vercel) +- [Vercel Deployment Docs](https://vercel.com/docs) +- [Vercel Custom Domain Docs](https://vercel.com/docs/custom-domains) ### Stdlib diff --git a/docs/guide/installation.md b/docs/guide/installation.md index c35003e888..67a9838f6b 100644 --- a/docs/guide/installation.md +++ b/docs/guide/installation.md @@ -7,9 +7,6 @@ If you have the previous `vue-cli` (1.x or 2.x) package installed globally, you ::: tip Node Version Requirement Vue CLI 4.x requires [Node.js](https://nodejs.org/) version 8.9 or above (v10+ recommended). You can manage multiple versions of Node on the same machine with [n](https://github.com/tj/n), [nvm](https://github.com/creationix/nvm) or [nvm-windows](https://github.com/coreybutler/nvm-windows). - -As Node.js v8 has reached end-of-life, it's now recommended to use Node.js v10+ for best compatibility. -If you have to stay with Node.js v8, please make sure npm v6 is used as the default package manager. (`npm -v` to check the version, and `vue config --set packageManager npm` to set the default package manager.) ::: To install the new package, use one of the following commands. You need administrator privileges to execute these unless npm was installed on your system through a Node.js version manager (e.g. n or nvm). diff --git a/docs/guide/webpack.md b/docs/guide/webpack.md index 38b4015f15..e65cd03b03 100644 --- a/docs/guide/webpack.md +++ b/docs/guide/webpack.md @@ -160,6 +160,11 @@ You can redirect the output into a file for easier inspection: ``` bash vue inspect > output.js ``` +By default, `inspect` command will show the output for development config. To see the production configuration, you need to run + +``` bash +vue inspect --mode production > output.prod.js +``` Note the output is not a valid webpack config file, it's a serialized format only meant for inspection. diff --git a/docs/zh/guide/build-targets.md b/docs/zh/guide/build-targets.md index a0cd4d795c..b7a6afc456 100644 --- a/docs/zh/guide/build-targets.md +++ b/docs/zh/guide/build-targets.md @@ -144,3 +144,20 @@ dist/foo.1.js 5.24 kb 1.64 kb ``` + +## 在构建时使用 vuex +在构建 [Web Components 组件](#web-components-组件)或[库](#库)时,入口点不是 `main.js` ,而是 `entry-wc.js` 文件,该文件由此生成: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/commands/build/resolveWcEntry.js + +因此,要在 Web Components 组件的目标中使用 vuex ,你需要在 `App.vue` 中初始化存储 (store): +``` js +import store from './store' + +// ... + +export default { + store, + name: 'App', + // ... +} +``` + diff --git a/docs/zh/guide/installation.md b/docs/zh/guide/installation.md index 0027230b13..d337264aea 100644 --- a/docs/zh/guide/installation.md +++ b/docs/zh/guide/installation.md @@ -7,9 +7,6 @@ Vue CLI 的包名称由 `vue-cli` 改成了 `@vue/cli`。 ::: tip Node 版本要求 Vue CLI 4.x 需要 [Node.js](https://nodejs.org/) v8.9 或更高版本 (推荐 v10 以上)。你可以使用 [n](https://github.com/tj/n),[nvm](https://github.com/creationix/nvm) 或 [nvm-windows](https://github.com/coreybutler/nvm-windows) 在同一台电脑中管理多个 Node 版本。 - -由于 Node.js v8 已不再维护,我们建议使用 Node.js v10 以上的版本,以保证最佳的兼容性。 -如果暂时无法升级 Node.js 版本,请使用 npm v6 作为默认的包管理工具。(可以用 `npm -v` 检查 npm 版本,然后运行 `vue config --set packageManager npm` 以设置默认包管理工具。) ::: 可以使用下列任一命令安装这个新的包: diff --git a/lerna.json b/lerna.json index 842a2727d4..ba6ede363b 100644 --- a/lerna.json +++ b/lerna.json @@ -1,7 +1,7 @@ { "npmClient": "yarn", "useWorkspaces": true, - "version": "4.5.6", + "version": "4.5.7", "packages": [ "packages/@vue/babel-preset-app", "packages/@vue/cli*", diff --git a/packages/@vue/babel-preset-app/package.json b/packages/@vue/babel-preset-app/package.json index fe6b9f83e9..fcda2bda33 100644 --- a/packages/@vue/babel-preset-app/package.json +++ b/packages/@vue/babel-preset-app/package.json @@ -1,6 +1,6 @@ { "name": "@vue/babel-preset-app", - "version": "4.5.6", + "version": "4.5.7", "description": "babel-preset-app for vue-cli", "main": "index.js", "publishConfig": { diff --git a/packages/@vue/cli-init/package.json b/packages/@vue/cli-init/package.json index 6284b42028..15a5ef9b93 100644 --- a/packages/@vue/cli-init/package.json +++ b/packages/@vue/cli-init/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-init", - "version": "4.5.6", + "version": "4.5.7", "description": "init addon for vue-cli", "main": "index.js", "publishConfig": { diff --git a/packages/@vue/cli-overlay/package.json b/packages/@vue/cli-overlay/package.json index 6cf4381f1f..5aa4c12b06 100644 --- a/packages/@vue/cli-overlay/package.json +++ b/packages/@vue/cli-overlay/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-overlay", - "version": "4.5.6", + "version": "4.5.7", "description": "error overlay & dev server middleware for vue-cli", "main": "dist/client.js", "files": [ diff --git a/packages/@vue/cli-plugin-babel/package.json b/packages/@vue/cli-plugin-babel/package.json index 927bc7f860..3407f3b1d4 100644 --- a/packages/@vue/cli-plugin-babel/package.json +++ b/packages/@vue/cli-plugin-babel/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-babel", - "version": "4.5.6", + "version": "4.5.7", "description": "babel plugin for vue-cli", "main": "index.js", "repository": { @@ -21,8 +21,8 @@ "homepage": "https://github.com/vuejs/vue-cli/tree/dev/packages/@vue/cli-plugin-babel#readme", "dependencies": { "@babel/core": "^7.11.0", - "@vue/babel-preset-app": "^4.5.6", - "@vue/cli-shared-utils": "^4.5.6", + "@vue/babel-preset-app": "^4.5.7", + "@vue/cli-shared-utils": "^4.5.7", "babel-loader": "^8.1.0", "cache-loader": "^4.1.0", "thread-loader": "^2.1.3", @@ -32,7 +32,7 @@ "@vue/cli-service": "^3.0.0 || ^4.0.0-0" }, "devDependencies": { - "jscodeshift": "^0.9.0" + "jscodeshift": "^0.10.0" }, "publishConfig": { "access": "public" diff --git a/packages/@vue/cli-plugin-e2e-cypress/package.json b/packages/@vue/cli-plugin-e2e-cypress/package.json index f335307c3e..7f42be071b 100644 --- a/packages/@vue/cli-plugin-e2e-cypress/package.json +++ b/packages/@vue/cli-plugin-e2e-cypress/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-e2e-cypress", - "version": "4.5.6", + "version": "4.5.7", "description": "e2e-cypress plugin for vue-cli", "main": "index.js", "repository": { @@ -23,7 +23,7 @@ "access": "public" }, "dependencies": { - "@vue/cli-shared-utils": "^4.5.6", + "@vue/cli-shared-utils": "^4.5.7", "cypress": "^3.8.3", "eslint-plugin-cypress": "^2.10.3" }, diff --git a/packages/@vue/cli-plugin-e2e-nightwatch/package.json b/packages/@vue/cli-plugin-e2e-nightwatch/package.json index 98fe185613..2049e3cfcb 100644 --- a/packages/@vue/cli-plugin-e2e-nightwatch/package.json +++ b/packages/@vue/cli-plugin-e2e-nightwatch/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-e2e-nightwatch", - "version": "4.5.6", + "version": "4.5.7", "description": "e2e-nightwatch plugin for vue-cli", "main": "index.js", "repository": { @@ -23,7 +23,7 @@ "access": "public" }, "dependencies": { - "@vue/cli-shared-utils": "^4.5.6", + "@vue/cli-shared-utils": "^4.5.7", "deepmerge": "^4.2.2", "nightwatch": "^1.3.5" }, diff --git a/packages/@vue/cli-plugin-e2e-webdriverio/package.json b/packages/@vue/cli-plugin-e2e-webdriverio/package.json index d53411e40e..a45613d3a1 100644 --- a/packages/@vue/cli-plugin-e2e-webdriverio/package.json +++ b/packages/@vue/cli-plugin-e2e-webdriverio/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-e2e-webdriverio", - "version": "4.5.6", + "version": "4.5.7", "description": "e2e-webdriverio plugin for vue-cli", "main": "index.js", "repository": { @@ -26,7 +26,7 @@ }, "dependencies": { "@types/mocha": "^8.0.1", - "@vue/cli-shared-utils": "^4.5.6", + "@vue/cli-shared-utils": "^4.5.7", "@wdio/cli": "^6.1.11", "@wdio/local-runner": "^6.1.11", "@wdio/mocha-framework": "^6.1.8", diff --git a/packages/@vue/cli-plugin-eslint/package.json b/packages/@vue/cli-plugin-eslint/package.json index 8793142fd2..2b04357631 100644 --- a/packages/@vue/cli-plugin-eslint/package.json +++ b/packages/@vue/cli-plugin-eslint/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-eslint", - "version": "4.5.6", + "version": "4.5.7", "description": "eslint plugin for vue-cli", "main": "index.js", "repository": { @@ -23,7 +23,7 @@ "access": "public" }, "dependencies": { - "@vue/cli-shared-utils": "^4.5.6", + "@vue/cli-shared-utils": "^4.5.7", "eslint-loader": "^2.2.1", "globby": "^9.2.0", "inquirer": "^7.1.0", diff --git a/packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js b/packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js index 070be9e4a7..1f349b9416 100644 --- a/packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js +++ b/packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js @@ -30,16 +30,16 @@ test('pwa', async () => { const index = await project.read('dist/index.html') // should split and preload app.js & vendor.js - expect(index).toMatch(/]+js\/app[^>]+\.js rel=preload as=script>/) - expect(index).toMatch(/]+js\/chunk-vendors[^>]+\.js rel=preload as=script>/) + expect(index).toMatch(/]+js\/app[^>]+\.js" rel="preload" as="script">/) + expect(index).toMatch(/]+js\/chunk-vendors[^>]+\.js" rel="preload" as="script">/) // should preload css - expect(index).toMatch(/]+app[^>]+\.css rel=preload as=style>/) + expect(index).toMatch(/]+app[^>]+\.css" rel="preload" as="style">/) // PWA specific directives - expect(index).toMatch(``) + expect(index).toMatch(``) // favicon is not minified because it's technically a comment expect(index).toMatch(``) - expect(index).toMatch(``) + expect(index).toMatch(``) // should import service worker script const main = await project.read('src/main.js') diff --git a/packages/@vue/cli-plugin-pwa/package.json b/packages/@vue/cli-plugin-pwa/package.json index 8626c59f28..2674e4c6d3 100644 --- a/packages/@vue/cli-plugin-pwa/package.json +++ b/packages/@vue/cli-plugin-pwa/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-pwa", - "version": "4.5.6", + "version": "4.5.7", "description": "pwa plugin for vue-cli", "main": "index.js", "repository": { @@ -23,7 +23,7 @@ "access": "public" }, "dependencies": { - "@vue/cli-shared-utils": "^4.5.6", + "@vue/cli-shared-utils": "^4.5.7", "webpack": "^4.0.0", "workbox-webpack-plugin": "^4.3.1" }, diff --git a/packages/@vue/cli-plugin-router/package.json b/packages/@vue/cli-plugin-router/package.json index 11164d57c7..d71c7f4b3e 100644 --- a/packages/@vue/cli-plugin-router/package.json +++ b/packages/@vue/cli-plugin-router/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-router", - "version": "4.5.6", + "version": "4.5.7", "description": "router plugin for vue-cli", "main": "index.js", "repository": { @@ -23,10 +23,10 @@ "access": "public" }, "dependencies": { - "@vue/cli-shared-utils": "^4.5.6" + "@vue/cli-shared-utils": "^4.5.7" }, "devDependencies": { - "@vue/cli-test-utils": "^4.5.6" + "@vue/cli-test-utils": "^4.5.7" }, "peerDependencies": { "@vue/cli-service": "^3.0.0 || ^4.0.0-0" diff --git a/packages/@vue/cli-plugin-typescript/codemods/__testfixtures__/shims-vue.input.ts b/packages/@vue/cli-plugin-typescript/codemods/__testfixtures__/shims-vue.input.ts new file mode 100644 index 0000000000..798e8fcfac --- /dev/null +++ b/packages/@vue/cli-plugin-typescript/codemods/__testfixtures__/shims-vue.input.ts @@ -0,0 +1,5 @@ +declare module '*.vue' { + import { defineComponent } from 'vue'; + const component: ReturnType; + export default component; +} diff --git a/packages/@vue/cli-plugin-typescript/codemods/__testfixtures__/shims-vue.output.ts b/packages/@vue/cli-plugin-typescript/codemods/__testfixtures__/shims-vue.output.ts new file mode 100644 index 0000000000..40f3f4bdf7 --- /dev/null +++ b/packages/@vue/cli-plugin-typescript/codemods/__testfixtures__/shims-vue.output.ts @@ -0,0 +1,5 @@ +declare module '*.vue' { + import { DefineComponent } from 'vue'; + const component: DefineComponent; + export default component; +} diff --git a/packages/@vue/cli-plugin-typescript/codemods/__tests__/migrateComponentType.spec.js b/packages/@vue/cli-plugin-typescript/codemods/__tests__/migrateComponentType.spec.js new file mode 100644 index 0000000000..ebf0a9297b --- /dev/null +++ b/packages/@vue/cli-plugin-typescript/codemods/__tests__/migrateComponentType.spec.js @@ -0,0 +1,5 @@ +jest.autoMockOff() + +const { defineTest } = require('jscodeshift/dist/testUtils') + +defineTest(__dirname, 'migrateComponentType', null, 'shims-vue', { parser: 'ts' }) diff --git a/packages/@vue/cli-plugin-typescript/codemods/migrateComponentType.js b/packages/@vue/cli-plugin-typescript/codemods/migrateComponentType.js new file mode 100644 index 0000000000..7f892b2de1 --- /dev/null +++ b/packages/@vue/cli-plugin-typescript/codemods/migrateComponentType.js @@ -0,0 +1,93 @@ +// `shims-vue.d.ts` for Vue 3, generated by CLI 4.5.0-4.5.6, uses the following declaration: +// `component: ReturnType` + +// So needs to update to: +// `component: DefineComponent` + +module.exports = function migrateComponentType (file, api) { + const j = api.jscodeshift + const root = j(file.source) + + const useDoubleQuote = root.find(j.StringLiteral).some(({ node }) => node.extra.raw.startsWith('"')) + + const tsmodule = root.find(j.TSModuleDeclaration, { + id: { + value: '*.vue' + } + }) + + const componentDecl = tsmodule.find(j.VariableDeclarator, { + id: { + name: 'component', + typeAnnotation: { + typeAnnotation: { + typeName: { + name: 'ReturnType' + }, + typeParameters: { + params: { + 0: { + exprName: { + name: 'defineComponent' + } + } + } + } + } + } + } + }) + + if (componentDecl.length !== 1) { + return file.source + } + + // update the component type + componentDecl.forEach(({ node }) => { + node.id.typeAnnotation = j.tsTypeAnnotation( + j.tsTypeReference(j.identifier('DefineComponent')) + ) + }) + + // insert DefineComponent type import + const importDeclFromVue = tsmodule.find(j.ImportDeclaration, { + source: { + value: 'vue' + } + }) + importDeclFromVue + .get(0) + .node.specifiers.push(j.importSpecifier(j.identifier('DefineComponent'))) + + // remove defineComponent import if unused + const defineComponentUsages = tsmodule + .find(j.Identifier, { name: 'defineComponent' }) + .filter((identifierPath) => { + const parent = identifierPath.parent.node + + // Ignore the import specifier + if ( + j.ImportDefaultSpecifier.check(parent) || + j.ImportSpecifier.check(parent) || + j.ImportNamespaceSpecifier.check(parent) + ) { + return false + } + }) + if (defineComponentUsages.length === 0) { + tsmodule + .find(j.ImportSpecifier, { + local: { + name: 'defineComponent' + } + }) + .remove() + } + + return root.toSource({ + lineTerminator: '\n', + quote: useDoubleQuote ? 'double' : 'single' + }) +} + +module.exports.parser = 'ts' diff --git a/packages/@vue/cli-plugin-typescript/generator/template-vue3/src/shims-vue.d.ts b/packages/@vue/cli-plugin-typescript/generator/template-vue3/src/shims-vue.d.ts index 32a1b5cd40..a99cf76cc7 100644 --- a/packages/@vue/cli-plugin-typescript/generator/template-vue3/src/shims-vue.d.ts +++ b/packages/@vue/cli-plugin-typescript/generator/template-vue3/src/shims-vue.d.ts @@ -1,5 +1,5 @@ declare module '*.vue' { - import { defineComponent } from 'vue' - const component: ReturnType + import type { DefineComponent } from 'vue' + const component: DefineComponent export default component } diff --git a/packages/@vue/cli-plugin-typescript/migrator/index.js b/packages/@vue/cli-plugin-typescript/migrator/index.js index a28ea4d578..bfe935eabd 100644 --- a/packages/@vue/cli-plugin-typescript/migrator/index.js +++ b/packages/@vue/cli-plugin-typescript/migrator/index.js @@ -1,4 +1,4 @@ -module.exports = api => { +module.exports = (api, options, rootOptions) => { api.extendPackage( { devDependencies: { @@ -7,4 +7,9 @@ module.exports = api => { }, { warnIncompatibleVersions: false } ) + + // update vue 3 typescript shim + if (rootOptions.vueVersion === 3) { + api.transformScript('src/shims-vue.d.ts', require('../codemods/migrateComponentType')) + } } diff --git a/packages/@vue/cli-plugin-typescript/package.json b/packages/@vue/cli-plugin-typescript/package.json index 4552efec77..66a783aec5 100644 --- a/packages/@vue/cli-plugin-typescript/package.json +++ b/packages/@vue/cli-plugin-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-typescript", - "version": "4.5.6", + "version": "4.5.7", "description": "typescript plugin for vue-cli", "main": "index.js", "repository": { @@ -24,7 +24,7 @@ }, "dependencies": { "@types/webpack-env": "^1.15.2", - "@vue/cli-shared-utils": "^4.5.6", + "@vue/cli-shared-utils": "^4.5.7", "cache-loader": "^4.1.0", "fork-ts-checker-webpack-plugin": "^3.1.1", "globby": "^9.2.0", @@ -51,6 +51,7 @@ "@types/chai": "^4.2.11", "@types/jest": "^24.0.19", "@types/mocha": "^5.2.6", + "jscodeshift": "^0.10.0", "typescript": "~3.9.3", "vue-class-component": "^7.2.3", "vue-property-decorator": "^8.4.2" diff --git a/packages/@vue/cli-plugin-unit-jest/package.json b/packages/@vue/cli-plugin-unit-jest/package.json index 8ebe2ceae0..97703b4ebf 100644 --- a/packages/@vue/cli-plugin-unit-jest/package.json +++ b/packages/@vue/cli-plugin-unit-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-unit-jest", - "version": "4.5.6", + "version": "4.5.7", "description": "unit-jest plugin for vue-cli", "main": "index.js", "repository": { @@ -26,7 +26,7 @@ "@babel/core": "^7.11.0", "@babel/plugin-transform-modules-commonjs": "^7.9.6", "@types/jest": "^24.0.19", - "@vue/cli-shared-utils": "^4.5.6", + "@vue/cli-shared-utils": "^4.5.7", "babel-core": "^7.0.0-bridge.0", "babel-jest": "^24.9.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2", diff --git a/packages/@vue/cli-plugin-unit-mocha/package.json b/packages/@vue/cli-plugin-unit-mocha/package.json index e8796dc879..3bd6844661 100644 --- a/packages/@vue/cli-plugin-unit-mocha/package.json +++ b/packages/@vue/cli-plugin-unit-mocha/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-unit-mocha", - "version": "4.5.6", + "version": "4.5.7", "description": "mocha unit testing plugin for vue-cli", "main": "index.js", "repository": { @@ -22,7 +22,7 @@ }, "homepage": "https://github.com/vuejs/vue-cli/tree/dev/packages/@vue/cli-plugin-unit-mocha#readme", "dependencies": { - "@vue/cli-shared-utils": "^4.5.6", + "@vue/cli-shared-utils": "^4.5.7", "jsdom": "^15.2.1", "jsdom-global": "^3.0.2", "mocha": "^6.2.2", diff --git a/packages/@vue/cli-plugin-vuex/package.json b/packages/@vue/cli-plugin-vuex/package.json index d2464c10f4..8ca4d9d86e 100644 --- a/packages/@vue/cli-plugin-vuex/package.json +++ b/packages/@vue/cli-plugin-vuex/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-plugin-vuex", - "version": "4.5.6", + "version": "4.5.7", "description": "Vuex plugin for vue-cli", "main": "index.js", "repository": { @@ -23,7 +23,7 @@ "access": "public" }, "devDependencies": { - "@vue/cli-test-utils": "^4.5.6" + "@vue/cli-test-utils": "^4.5.7" }, "peerDependencies": { "@vue/cli-service": "^3.0.0 || ^4.0.0-0" diff --git a/packages/@vue/cli-service-global/package.json b/packages/@vue/cli-service-global/package.json index cf7d2789df..415d3f2fe4 100644 --- a/packages/@vue/cli-service-global/package.json +++ b/packages/@vue/cli-service-global/package.json @@ -1,6 +1,6 @@ { "name": "@vue/cli-service-global", - "version": "4.5.6", + "version": "4.5.7", "description": "vue-cli-service global addon for vue-cli", "main": "index.js", "publishConfig": { @@ -22,9 +22,9 @@ }, "homepage": "https://github.com/vuejs/vue-cli/tree/dev/packages/@vue/cli-service-global#readme", "dependencies": { - "@vue/cli-plugin-babel": "^4.5.6", - "@vue/cli-plugin-eslint": "^4.5.6", - "@vue/cli-service": "^4.5.6", + "@vue/cli-plugin-babel": "^4.5.7", + "@vue/cli-plugin-eslint": "^4.5.7", + "@vue/cli-service": "^4.5.7", "babel-eslint": "^10.1.0", "chalk": "^3.0.0", "core-js": "^3.6.5", diff --git a/packages/@vue/cli-service/__tests__/build.spec.js b/packages/@vue/cli-service/__tests__/build.spec.js index 070d29a559..85948f1217 100644 --- a/packages/@vue/cli-service/__tests__/build.spec.js +++ b/packages/@vue/cli-service/__tests__/build.spec.js @@ -28,19 +28,19 @@ test('build', async () => { const index = await project.read('dist/index.html') // should split and preload app.js & vendor.js - expect(index).toMatch(/]+js\/app[^>]+\.js rel=preload as=script>/) - expect(index).toMatch(/]+js\/chunk-vendors[^>]+\.js rel=preload as=script>/) + expect(index).toMatch(/]+js\/app[^>]+\.js" rel="preload" as="script">/) + expect(index).toMatch(/]+js\/chunk-vendors[^>]+\.js" rel="preload" as="script">/) // should preload css - expect(index).toMatch(/]+app[^>]+\.css rel=preload as=style>/) + expect(index).toMatch(/]+app[^>]+\.css" rel="preload" as="style">/) // should inject scripts - expect(index).toMatch(/