@@ -52,13 +52,13 @@ export default {
52
52
createRouter (location ) {
53
53
if (this .exportAsTypescript === " on" ) {
54
54
fs .writeFileSync (
55
- path .join (location, " src" , " router.ts" ),
55
+ path .join (location, " src" , " router" , " index .ts" ),
56
56
this .createRouterImports (this .componentMap [" App" ].children ) +
57
57
this .createExport (this .componentMap [" App" ].children )
58
58
);
59
59
} else {
60
60
fs .writeFileSync (
61
- path .join (location, " src" , " router.js" ),
61
+ path .join (location, " src" , " router" , " index .js" ),
62
62
this .createRouterImports (this .componentMap [" App" ].children ) +
63
63
this .createExport (this .componentMap [" App" ].children )
64
64
);
@@ -71,25 +71,20 @@ export default {
71
71
createRouterImports (appChildren ) {
72
72
let str = " import { createRouter, createWebHistory } from 'vue-router';\n " ;
73
73
appChildren .forEach ((child ) => {
74
- str += ` import ${ child} from './views/${ child} .vue';\n ` ;
74
+ str += ` import ${ child} from '.. /views/${ child} .vue';\n ` ;
75
75
});
76
76
return str;
77
77
},
78
78
/**
79
79
* @description creates the `export default` code in <script>
80
80
*/
81
81
createExport (appChildren ) {
82
- let str;
83
- if (this .exportAsTypescript === " on" ) {
84
- str = " export default createRouter({\n\t history: createWebHistory(process.env.BASE_URL),\n\t routes: [\n " ;
85
- } else {
86
- str = " export default createRouter({\n\t history: createWebHistory(),\n\t base: process.env.BASE_URL,\n\t routes: [\n " ;
87
- }
82
+ let str = " export default createRouter({\n\t history: createWebHistory(import.meta.env.BASE_URL),\n\t routes: [\n " ;
88
83
appChildren .forEach ((child ) => {
89
84
if (child === " HomeView" ) {
90
85
str += ` \t\t {\n\t\t\t path: '/',\n\t\t\t name:'${ child} ',\n\t\t\t component:${ child} \n\t\t },\n ` ;
91
86
} else {
92
- str += ` \t\t {\n\t\t\t path: '/${ child} ',\n\t\t\t name:'${ child} ',\n\t\t\t component: ${ child} \n\t\t },\n ` ;
87
+ str += ` \t\t {\n\t\t\t path: '/${ child} ',\n\t\t\t name:'${ child} ',\n\t\t\t component: () => import('../views/ ${ child} .vue') \n\t\t },\n ` ;
93
88
}
94
89
});
95
90
str += ` \t ]\n })\n ` ;
@@ -347,19 +342,23 @@ export default {
347
342
str += ` \n\t <meta charset="utf-8">` ;
348
343
str += ` \n\t <meta http-equiv="X-UA-Compatible" content="IE=edge">` ;
349
344
str += ` \n\t <meta name="viewport" content="width=device-width,initial-scale=1.0">` ;
350
- str += ` \n\t <link rel="icon" href="<%= BASE_URL %> favicon.ico">` ;
351
- str += ` \n\t <title>New Vue Project</title>` ;
345
+ str += ` \n\t <link rel="icon" href="/ favicon.ico">` ;
346
+ str += ` \n\t <title>New OverVue Project</title>` ;
352
347
str += ` \n </head>\n\n ` ;
353
348
str += ` <body>` ;
354
349
str += ` \n\t <noscript>` ;
355
350
str += ` \n\t\t <strong>We're sorry but vue-boiler-plate-routes doesn't work properly without JavaScript enabled. Please enable it
356
351
to continue.</strong>` ;
357
352
str += ` \n\t </noscript>` ;
358
353
str += ` \n\t <div id="app"></div>` ;
359
- str += ` \n\t <!-- built files will be auto injected -->` ;
354
+ if (this .exportAsTypescript === " on" ){
355
+ str += ` \n\t <script type="module" src="/src/main.ts"><\/ script>` ;
356
+ } else {
357
+ str += ` \n\t <script type="module" src="/src/main.js"><\/ script>` ;
358
+ }
360
359
str += ` \n </body>\n\n ` ;
361
360
str += ` </html>\n ` ;
362
- fs .writeFileSync (path .join (location, " public " , " index.html" ), str);
361
+ fs .writeFileSync (path .join (location, " index.html" ), str);
363
362
},
364
363
// creates main.js boilerplate
365
364
createMainFile (location ) {
@@ -379,83 +378,105 @@ export default {
379
378
}
380
379
},
381
380
// create babel file
382
- createBabel (location ) {
383
- let str = ` module.exports = {` ;
384
- str += ` \n\t presets: [` ;
385
- str += ` \n\t\t '@vue/app'` ;
386
- str += ` \n\t ]` ;
387
- str += ` \n }` ;
381
+ createViteConfig (location ) {
382
+ let str = ` import { fileURLToPath, URL } from 'url';\n\n ` ;
383
+ str += ` import { defineConfig } from 'vite';\n ` ;
384
+ str += ` import vue from '@vitejs/plugin-vue';\n\n ` ;
385
+ str += ` export default defineConfig({\n `
386
+ str += ` \t plugins: [vue()],\n `
387
+ str += ` \t resolve: {\n `
388
+ str += ` \t\t alias: {\n `
389
+ str += ` \t\t\t '@': fileURLToPath(new URL('./src', import.meta.url))\n `
390
+ str += ` \t\t }\n\t }\n })`
391
+
388
392
// if using typescript, export with .ts extension
389
393
if (this .exportAsTypescript === " on" ) {
390
- fs .writeFileSync (path .join (location, " src " , " babel .config.ts" ), str);
394
+ fs .writeFileSync (path .join (location, " vite .config.ts" ), str);
391
395
} else {
392
- fs .writeFileSync (path .join (location, " babel .config.js" ), str);
396
+ fs .writeFileSync (path .join (location, " vite .config.js" ), str);
393
397
}
394
398
},
399
+ createESLintRC (location ) {
400
+ let str;
401
+ if (this .exportAsTypescript === " on" ){
402
+ str += ` require("@rushstack/eslint-patch/modern-module-resolution");\n\n ` ;
403
+ }
404
+ str += ` module.exports = {\n ` ;
405
+ str += ` \t "root": true,\n ` ;
406
+ str += ` \t "extends": [\n ` ;
407
+ str += ` \t\t "plugin:vue/vue3-essential",\n `
408
+ str += ` \t\t "eslint:recommended"`
409
+ if (this .exportAsTypescript === " on" ){
410
+ str += ` ,\n\t\t "@vue/eslint-config-typescript/recommended"\n `
411
+ }
412
+ str += ` \n\t ],\n `
413
+ str += ` \t "env": {\n `
414
+ str += ` \t\t "vue/setup-compiler-macros": true\n `
415
+ str += ` \t }\n }`
416
+ fs .writeFileSync (path .join (location, " .eslintrc.cjs" ), str);
417
+ },
395
418
createTSConfig (location ) {
396
419
if (this .exportAsTypescript === " on" ) {
397
- let str = ` {\n\t "extends": "@vue/tsconfig/tsconfig.web.json",\n\t "include": ["src/**/*", "src/**/*.vue"],\n\t "compilerOptions": {\n\t\t "baseUrl": ".",\n\t\t "paths": {\n\t\t\t "@/*": ["./src/*"]\n\t\t }\n\t }\n }` ;
420
+ let str = ` {\n\t "extends": "@vue/tsconfig/tsconfig.web.json",\n\t "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],\n\t "compilerOptions": {\n\t\t "baseUrl": ".",\n\t\t "paths": {\n\t\t\t "@/*": ["./src/*"]\n\t\t }\n\t },` ;
421
+ str += ` \t "references": [\n `
422
+ str += ` \t\t {\n\t\t\t "path": "./tsconfig.vite-config.json"\n\t\t }\n\t ]\n }`
398
423
fs .writeFileSync (path .join (location, " tsconfig.json" ), str);
399
424
} else {
400
425
return ;
401
426
}
402
427
},
428
+ createTSViteConfig (location ) {
429
+ if (this .exportAsTypescript === " on" ) {
430
+ let str = ` {\n\t "extends": "@vue/tsconfig/tsconfig.node.json",\n\t "include": ["vite.config.*"],\n\t "compilerOptions": {\n\t\t "composite": true,\n\t\t "types": ["node", "viteset"]\n\t }\n }` ;
431
+ fs .writeFileSync (path .join (location, " tsconfig.vite-config.json" ), str);
432
+ } else {
433
+ return ;
434
+ }
435
+ },
436
+ createTSDeclaration (location ) {
437
+ if (this .exportAsTypescript === " on" ) {
438
+ let str = ` /// <reference types="vite/client" />` ;
439
+ fs .writeFileSync (path .join (location, " env.d.ts" ), str);
440
+ } else {
441
+ return ;
442
+ }
443
+ },
403
444
// create package.json file
404
445
createPackage (location ) {
405
446
let str = ` {` ;
406
- str += ` \n\t "name": "vue-boiler-plate-routes",` ;
407
- str += ` \n\t "version": "0.1.0",` ;
408
- str += ` \n\t "private": true,` ;
447
+ str += ` \n\t "name": "My-OverVue-Project",` ;
448
+ str += ` \n\t "version": "0.0.0",` ;
409
449
str += ` \n\t "scripts": {` ;
410
- str += ` \n\t\t "start": "vue-cli-service serve",` ;
411
- str += ` \n\t\t "build": "vue-cli-service build",` ;
412
- str += ` \n\t\t "lint": "vue-cli-service lint"` ;
450
+ str += ` \n\t\t "dev": "vite",` ;
451
+ if (this .exportAsTypescript === " on" ) {
452
+ str += ` \n\t\t "build": "vue-tsc --noEmit && vite build",` ;
453
+ str += ` \n\t\t "typecheck": "vue-tsc --noEmit",` ;
454
+ str += ` \n\t\t "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",` ;
455
+ } else {
456
+ str += ` \n\t\t "build": "vite build",` ;
457
+ str += ` \n\t\t "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore",` ;
458
+ }
459
+ str += ` \n\t\t "preview": "vite preview --port 5050"` ;
413
460
str += ` \n\t },` ;
414
461
str += ` \n\t "dependencies": {` ;
415
- str += ` \n\t\t "vue": "^3.2.26 ",` ;
462
+ str += ` \n\t\t "vue": "^3.2.31 ",` ;
416
463
str += ` \n\t\t "vue-router": "^4.0.12",` ;
417
464
str += ` \n\t\t "vuex": "^4.0.2"` ;
418
465
str += ` \n\t },` ;
419
466
str += ` \n\t "devDependencies": {` ;
420
- str += ` \n\t\t "@vue/cli-plugin-babel": "~4.5.0",` ;
421
- str += ` \n\t\t "@vue/cli-plugin-eslint": "~4.5.0",` ;
422
- str += ` \n\t\t "@vue/cli-service": "~4.5.0",` ;
423
- str += ` \n\t\t "babel-eslint": "^10.0.1",` ;
424
- str += ` \n\t\t "eslint": "^8.9.0",` ;
425
- str += ` \n\t\t "eslint-plugin-vue": "^8.4.1",` ;
426
- str += ` \n\t\t "@vue/compiler-sfc": "^3.0.0-0"` ;
467
+ str += ` \n\t\t "@vitejs/plugin-vue": "^2.2.2",` ;
468
+ str += ` \n\t\t "eslint": "^8.5.0",` ;
469
+ str += ` \n\t\t "eslint-plugin-vue": "^8.2.0",` ;
470
+ str += ` \n\t\t "vite": "^2.8.4"`
427
471
if (this .exportAsTypescript === " on" ) {
428
- str += ` ,\n\t\t "@vue/tsconfig": "^0.1.3",` ;
472
+ str += ` ,\n\t\t "@rushstack/eslint-patch": "^1.1.0",`
473
+ str += ` \n\t\t "@vue/tsconfig": "^0.1.3",` ;
429
474
str += ` \n\t\t "typescript": "~4.5.5",` ;
430
475
str += ` \n\t\t "vue-tsc": "^0.31.4",` ;
431
- str += ` \n\t\t "@babel/preset-typescript": "^7.16.7"` ; // not sure we need this?
476
+ str += ` \n\t\t "@types/node": "^16.11.25",` ;
477
+ str += ` \n\t\t "@vue/eslint-config-typescript": "^10.0.0"` ;
432
478
}
433
- str += ` \n\t },` ;
434
- str += ` \n\t "eslintConfig": {` ;
435
- str += ` \n\t\t "root": true,` ;
436
- str += ` \n\t\t "env": {` ;
437
- str += ` \n\t\t\t "node": true` ;
438
- str += ` \n\t\t },` ;
439
- str += ` \n\t\t "extends": [` ;
440
- str += ` \n\t\t\t "plugin:vue/essential",` ;
441
- str += ` \n\t\t\t "eslint:recommended"` ;
442
- str += ` \n\t\t ],` ;
443
- str += ` \n\t\t "rules": {},` ;
444
- str += ` \n\t\t "parserOptions": {` ;
445
- str += ` \n\t\t\t "parser": "babel-eslint"` ;
446
- str += ` \n\t\t }` ;
447
- str += ` \n\t },` ;
448
- str += ` \n\t "postcss": {` ;
449
- str += ` \n\t\t "plugins": {` ;
450
- str += ` \n\t\t\t "autoprefixer": {}` ;
451
- str += ` \n\t\t }` ;
452
- str += ` \n\t },` ;
453
- str += ` \n\t "browserslist": [` ;
454
- str += ` \n\t\t "> 1%",` ;
455
- str += ` \n\t\t "last 2 versions",` ;
456
- str += ` \n\t\t "not ie <= 8"` ;
457
- str += ` \n\t ]` ;
458
- str += ` \n }` ;
479
+ str += ` \n\t }\n }` ;
459
480
fs .writeFileSync (path .join (location, " package.json" ), str);
460
481
},
461
482
exportFile (data ) {
@@ -468,12 +489,16 @@ export default {
468
489
fs .mkdirSync (path .join (data, " src" , " assets" ));
469
490
fs .mkdirSync (path .join (data, " src" , " components" ));
470
491
fs .mkdirSync (path .join (data, " src" , " views" ));
492
+ fs .mkdirSync (path .join (data, " src" , " router" ));
471
493
}
472
494
// creating basic boilerplate for vue app
473
495
this .createIndexFile (data);
474
496
this .createMainFile (data);
475
- this .createBabel (data);
497
+ this .createViteConfig (data);
498
+ this .createESLintRC (data);
476
499
this .createTSConfig (data);
500
+ this .createTSViteConfig (data);
501
+ this .createTSDeclaration (data);
477
502
this .createPackage (data);
478
503
// exports images to the /assets folder
479
504
// eslint-disable-next-line no-unused-vars
0 commit comments