diff --git a/.browserslistrc b/.browserslistrc new file mode 100644 index 0000000..214388f --- /dev/null +++ b/.browserslistrc @@ -0,0 +1,3 @@ +> 1% +last 2 versions +not dead diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..3857599 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,31 @@ +module.exports = { + root: true, + env: { + node: true, + }, + extends: [ + "plugin:vue/vue3-essential", + "eslint:recommended", + "@vue/typescript/recommended", + "@vue/prettier", + "@vue/prettier/@typescript-eslint", + ], + parserOptions: { + ecmaVersion: 2020, + }, + rules: { + "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", + "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", + }, + overrides: [ + { + files: [ + "**/__tests__/*.{j,t}s?(x)", + "**/tests/unit/**/*.spec.{j,t}s?(x)", + ], + env: { + jest: true, + }, + }, + ], +}; diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ec8281 --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +.DS_Store +node_modules +/dist + +/tests/e2e/videos/ +/tests/e2e/screenshots/ + + +# local env files +.env.local +.env.*.local + +# Log files +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/README.md b/README.md index 161ddb4..117681c 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,34 @@ -## 目前已有脚手架列表 +# nicecode-vue-cli -| 名称 | 说明 | 技术栈 | -| ------- | --------------------------- | --------------------- | -| nextJs | 基于 React 的服务端渲染方案 | nextJs + axios + antd | -| ReactJs | 基于 React 的业务型脚手架 | umiJs + axios + antd | -| TaroJs | 基于 React 的多端适配方案 | TaroJs 全家桶 | -| Vue | 基于 Vue 的业务型脚手架 | vueJs 全家桶 | -| Gulp | 基于 Gulp 的清凉型脚手架 | -- | - -## 快速上手 - -### 1. 安装相关依赖 - -```js -// 推荐 -yarn global add @nicecode/cli - -// or -// npm install @nicecode/cli -g +## Project setup +``` +yarn install ``` -### 2. 运行命令 - -```js -// 查看脚手架版本号,是否安装成功 -nice - V +### Compiles and hot-reloads for development +``` +yarn serve ``` -### 3. 创建项目 - -```js -nice create ${项目名称} +### Compiles and minifies for production ``` +yarn build +``` + +### Run your unit tests +``` +yarn test:unit +``` + +### Run your end-to-end tests +``` +yarn test:e2e +``` + +### Lints and fixes files +``` +yarn lint +``` + +### Customize configuration +See [Configuration Reference](https://cli.vuejs.org/config/). diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..e3b489e --- /dev/null +++ b/babel.config.js @@ -0,0 +1,11 @@ +module.exports = { + presets: ["@vue/cli-plugin-babel/preset"], + plugins: [ + [ + "import", { + "libraryName": "@nicecode/tools", + "camel2DashComponentName": false + } + ] + ] +}; diff --git a/cypress.json b/cypress.json new file mode 100644 index 0000000..470c720 --- /dev/null +++ b/cypress.json @@ -0,0 +1,3 @@ +{ + "pluginsFile": "tests/e2e/plugins/index.js" +} diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..075155a --- /dev/null +++ b/jest.config.js @@ -0,0 +1,6 @@ +module.exports = { + preset: "@vue/cli-plugin-unit-jest/presets/typescript-and-babel", + transform: { + "^.+\\.vue$": "vue-jest", + }, +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..be65a2a --- /dev/null +++ b/package.json @@ -0,0 +1,51 @@ +{ + "name": "nicecode-vue-cli", + "version": "0.1.0", + "private": true, + "author": "dev <710328466@qq.com>", + "scripts": { + "start": "vue-cli-service serve", + "build": "vue-cli-service build --report", + "test:unit": "vue-cli-service test:unit", + "test:e2e": "vue-cli-service test:e2e", + "lint": "vue-cli-service lint" + }, + "dependencies": { + "core-js": "^3.6.5", + "register-service-worker": "^1.7.1", + "vue": "^3.0.0", + "vue-class-component": "^8.0.0-0", + "vue-router": "^4.0.0-0", + "vuex": "^4.0.0-0" + }, + "devDependencies": { + "@types/jest": "^24.0.19", + "@typescript-eslint/eslint-plugin": "^4.18.0", + "@typescript-eslint/parser": "^4.18.0", + "@vue/cli-plugin-babel": "~4.5.0", + "@vue/cli-plugin-e2e-cypress": "~4.5.0", + "@vue/cli-plugin-eslint": "~4.5.0", + "@vue/cli-plugin-pwa": "~4.5.0", + "@vue/cli-plugin-router": "~4.5.0", + "@vue/cli-plugin-typescript": "~4.4.0", + "@vue/cli-plugin-unit-jest": "~4.5.0", + "@vue/cli-plugin-vuex": "~4.5.0", + "@vue/cli-service": "~4.5.0", + "@vue/compiler-sfc": "^3.0.0", + "@vue/eslint-config-prettier": "^6.0.0", + "@vue/eslint-config-typescript": "^7.0.0", + "@vue/test-utils": "^2.0.0-0", + "babel-plugin-import": "^1.13.3", + "eslint": "^6.7.2", + "eslint-plugin-prettier": "^3.3.1", + "eslint-plugin-vue": "^7.0.0", + "prettier": "^2.2.1", + "stylus": "^0.54.7", + "stylus-loader": "^3.0.2", + "typescript": "~4.1.5", + "vue-jest": "^5.0.0-0", + "vue-loader-v16": "^16.0.0-beta.5.4", + "webpack": "^4.44.2", + "webpack-bundle-analyzer": "^4.4.2" + } +} diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..df36fcf Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/img/icons/android-chrome-192x192.png b/public/img/icons/android-chrome-192x192.png new file mode 100644 index 0000000..b02aa64 Binary files /dev/null and b/public/img/icons/android-chrome-192x192.png differ diff --git a/public/img/icons/android-chrome-512x512.png b/public/img/icons/android-chrome-512x512.png new file mode 100644 index 0000000..06088b0 Binary files /dev/null and b/public/img/icons/android-chrome-512x512.png differ diff --git a/public/img/icons/android-chrome-maskable-192x192.png b/public/img/icons/android-chrome-maskable-192x192.png new file mode 100644 index 0000000..791e9c8 Binary files /dev/null and b/public/img/icons/android-chrome-maskable-192x192.png differ diff --git a/public/img/icons/android-chrome-maskable-512x512.png b/public/img/icons/android-chrome-maskable-512x512.png new file mode 100644 index 0000000..5f2098e Binary files /dev/null and b/public/img/icons/android-chrome-maskable-512x512.png differ diff --git a/public/img/icons/apple-touch-icon-120x120.png b/public/img/icons/apple-touch-icon-120x120.png new file mode 100644 index 0000000..1427cf6 Binary files /dev/null and b/public/img/icons/apple-touch-icon-120x120.png differ diff --git a/public/img/icons/apple-touch-icon-152x152.png b/public/img/icons/apple-touch-icon-152x152.png new file mode 100644 index 0000000..f24d454 Binary files /dev/null and b/public/img/icons/apple-touch-icon-152x152.png differ diff --git a/public/img/icons/apple-touch-icon-180x180.png b/public/img/icons/apple-touch-icon-180x180.png new file mode 100644 index 0000000..404e192 Binary files /dev/null and b/public/img/icons/apple-touch-icon-180x180.png differ diff --git a/public/img/icons/apple-touch-icon-60x60.png b/public/img/icons/apple-touch-icon-60x60.png new file mode 100644 index 0000000..cf10a56 Binary files /dev/null and b/public/img/icons/apple-touch-icon-60x60.png differ diff --git a/public/img/icons/apple-touch-icon-76x76.png b/public/img/icons/apple-touch-icon-76x76.png new file mode 100644 index 0000000..c500769 Binary files /dev/null and b/public/img/icons/apple-touch-icon-76x76.png differ diff --git a/public/img/icons/apple-touch-icon.png b/public/img/icons/apple-touch-icon.png new file mode 100644 index 0000000..03c0c5d Binary files /dev/null and b/public/img/icons/apple-touch-icon.png differ diff --git a/public/img/icons/favicon-16x16.png b/public/img/icons/favicon-16x16.png new file mode 100644 index 0000000..42af009 Binary files /dev/null and b/public/img/icons/favicon-16x16.png differ diff --git a/public/img/icons/favicon-32x32.png b/public/img/icons/favicon-32x32.png new file mode 100644 index 0000000..46ca04d Binary files /dev/null and b/public/img/icons/favicon-32x32.png differ diff --git a/public/img/icons/msapplication-icon-144x144.png b/public/img/icons/msapplication-icon-144x144.png new file mode 100644 index 0000000..7808237 Binary files /dev/null and b/public/img/icons/msapplication-icon-144x144.png differ diff --git a/public/img/icons/mstile-150x150.png b/public/img/icons/mstile-150x150.png new file mode 100644 index 0000000..3b37a43 Binary files /dev/null and b/public/img/icons/mstile-150x150.png differ diff --git a/public/img/icons/safari-pinned-tab.svg b/public/img/icons/safari-pinned-tab.svg new file mode 100644 index 0000000..e44c0d5 --- /dev/null +++ b/public/img/icons/safari-pinned-tab.svg @@ -0,0 +1,3 @@ + + + diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..2afd5e7 --- /dev/null +++ b/public/index.html @@ -0,0 +1,17 @@ + + + + + + + + <%= htmlWebpackPlugin.options.title %> + + + +
+ + + diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..eb05362 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git a/src/App.vue b/src/App.vue new file mode 100644 index 0000000..807ee57 --- /dev/null +++ b/src/App.vue @@ -0,0 +1,17 @@ + + + diff --git a/src/assets/logo.png b/src/assets/logo.png new file mode 100644 index 0000000..f3d2503 Binary files /dev/null and b/src/assets/logo.png differ diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue new file mode 100644 index 0000000..008189f --- /dev/null +++ b/src/components/HelloWorld.vue @@ -0,0 +1,35 @@ + + + + + + diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..e84d89d --- /dev/null +++ b/src/main.ts @@ -0,0 +1,10 @@ +import { createApp } from "vue"; +import App from "./App.vue"; +import "./registerServiceWorker"; +import router from "./router"; +import store from "./store"; + +createApp(App) + .use(store) + .use(router) + .mount("#app"); diff --git a/src/registerServiceWorker.ts b/src/registerServiceWorker.ts new file mode 100644 index 0000000..1473a0a --- /dev/null +++ b/src/registerServiceWorker.ts @@ -0,0 +1,34 @@ +/* eslint-disable no-console */ + +import { register } from "register-service-worker"; + +if (process.env.NODE_ENV === "production") { + register(`${process.env.BASE_URL}service-worker.js`, { + ready() { + console.log( + "App is being served from cache by a service worker.\n" + + "For more details, visit https://goo.gl/AFskqB" + ); + }, + registered() { + console.log("Service worker has been registered."); + }, + cached() { + console.log("Content has been cached for offline use."); + }, + updatefound() { + console.log("New content is downloading."); + }, + updated() { + console.log("New content is available; please refresh."); + }, + offline() { + console.log( + "No internet connection found. App is running in offline mode." + ); + }, + error(error) { + console.error("Error during service worker registration:", error); + }, + }); +} diff --git a/src/router/index.ts b/src/router/index.ts new file mode 100644 index 0000000..8061482 --- /dev/null +++ b/src/router/index.ts @@ -0,0 +1,26 @@ +import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router"; +import Home from "../views/Home.vue"; + +const routes: Array = [ + { + path: "/", + name: "Home", + component: Home, + }, + { + path: "/about", + name: "About", + // route level code-splitting + // this generates a separate chunk (about.[hash].js) for this route + // which is lazy-loaded when the route is visited. + component: () => + import("../views/About.vue"), + }, +]; + +const router = createRouter({ + history: createWebHistory(process.env.BASE_URL), + routes, +}); + +export default router; diff --git a/src/shims-vue.d.ts b/src/shims-vue.d.ts new file mode 100644 index 0000000..3804a43 --- /dev/null +++ b/src/shims-vue.d.ts @@ -0,0 +1,6 @@ +/* eslint-disable */ +declare module '*.vue' { + import type { DefineComponent } from 'vue' + const component: DefineComponent<{}, {}, any> + export default component +} diff --git a/src/store/index.ts b/src/store/index.ts new file mode 100644 index 0000000..9e1c7d3 --- /dev/null +++ b/src/store/index.ts @@ -0,0 +1,8 @@ +import { createStore } from "vuex"; + +export default createStore({ + state: {}, + mutations: {}, + actions: {}, + modules: {}, +}); diff --git a/src/views/About.vue b/src/views/About.vue new file mode 100644 index 0000000..3fa2807 --- /dev/null +++ b/src/views/About.vue @@ -0,0 +1,5 @@ + diff --git a/src/views/Home.vue b/src/views/Home.vue new file mode 100644 index 0000000..4839bc1 --- /dev/null +++ b/src/views/Home.vue @@ -0,0 +1,19 @@ + + + diff --git a/tests/e2e/.eslintrc.js b/tests/e2e/.eslintrc.js new file mode 100644 index 0000000..2ee3017 --- /dev/null +++ b/tests/e2e/.eslintrc.js @@ -0,0 +1,10 @@ +module.exports = { + plugins: ["cypress"], + env: { + mocha: true, + "cypress/globals": true, + }, + rules: { + strict: "off", + }, +}; diff --git a/tests/e2e/plugins/index.js b/tests/e2e/plugins/index.js new file mode 100644 index 0000000..b32a680 --- /dev/null +++ b/tests/e2e/plugins/index.js @@ -0,0 +1,25 @@ +/* eslint-disable arrow-body-style */ +// https://docs.cypress.io/guides/guides/plugins-guide.html + +// if you need a custom webpack configuration you can uncomment the following import +// and then use the `file:preprocessor` event +// as explained in the cypress docs +// https://docs.cypress.io/api/plugins/preprocessors-api.html#Examples + +// /* eslint-disable import/no-extraneous-dependencies, global-require */ +// const webpack = require('@cypress/webpack-preprocessor') + +module.exports = (on, config) => { + // on('file:preprocessor', webpack({ + // webpackOptions: require('@vue/cli-service/webpack.config'), + // watchOptions: {} + // })) + + return Object.assign({}, config, { + fixturesFolder: "tests/e2e/fixtures", + integrationFolder: "tests/e2e/specs", + screenshotsFolder: "tests/e2e/screenshots", + videosFolder: "tests/e2e/videos", + supportFile: "tests/e2e/support/index.js", + }); +}; diff --git a/tests/e2e/specs/test.js b/tests/e2e/specs/test.js new file mode 100644 index 0000000..7073896 --- /dev/null +++ b/tests/e2e/specs/test.js @@ -0,0 +1,8 @@ +// https://docs.cypress.io/api/introduction/api.html + +describe("My First Test", () => { + it("Visits the app root url", () => { + cy.visit("/"); + cy.contains("h1", "Welcome to Your Vue.js + TypeScript App"); + }); +}); diff --git a/tests/e2e/support/commands.js b/tests/e2e/support/commands.js new file mode 100644 index 0000000..c1f5a77 --- /dev/null +++ b/tests/e2e/support/commands.js @@ -0,0 +1,25 @@ +// *********************************************** +// This example commands.js shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add("login", (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This is will overwrite an existing command -- +// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) diff --git a/tests/e2e/support/index.js b/tests/e2e/support/index.js new file mode 100644 index 0000000..d076cec --- /dev/null +++ b/tests/e2e/support/index.js @@ -0,0 +1,20 @@ +// *********************************************************** +// This example support/index.js is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import "./commands"; + +// Alternatively you can use CommonJS syntax: +// require('./commands') diff --git a/tests/unit/example.spec.ts b/tests/unit/example.spec.ts new file mode 100644 index 0000000..0811d8a --- /dev/null +++ b/tests/unit/example.spec.ts @@ -0,0 +1,12 @@ +import { shallowMount } from "@vue/test-utils"; +import HelloWorld from "@/components/HelloWorld.vue"; + +describe("HelloWorld.vue", () => { + it("renders props.msg when passed", () => { + const msg = "new message"; + const wrapper = shallowMount(HelloWorld, { + props: { msg }, + }); + expect(wrapper.text()).toMatch(msg); + }); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5c6ed5a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,41 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "strict": true, + "jsx": "preserve", + "importHelpers": true, + "moduleResolution": "node", + "experimentalDecorators": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "sourceMap": true, + "baseUrl": ".", + "types": [ + "webpack-env", + "jest" + ], + "paths": { + "@/*": [ + "src/*" + ] + }, + "lib": [ + "esnext", + "dom", + "dom.iterable", + "scripthost" + ] + }, + "include": [ + "src/**/*.ts", + "src/**/*.tsx", + "src/**/*.vue", + "tests/**/*.ts", + "tests/**/*.tsx" + ], + "exclude": [ + "node_modules" + ] +} diff --git a/vue.config.js b/vue.config.js new file mode 100644 index 0000000..80c08b5 --- /dev/null +++ b/vue.config.js @@ -0,0 +1,7 @@ +module.exports = { + chainWebpack: config => { + config + .plugin('webpack-bundle-analyzer') + .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin) + } +} \ No newline at end of file