@@ -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,22 +378,56 @@ 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);
395
+ } else {
396
+ fs .writeFileSync (path .join (location, " vite.config.js" ), str);
397
+ }
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
+ },
418
+ createTSViteConfig (location ) {
419
+ if (this .exportAsTypescript === " on" ) {
420
+ 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 }` ;
421
+ fs .writeFileSync (path .join (location, " tsconfig.vite-config.json" ), str);
391
422
} else {
392
- fs . writeFileSync ( path . join (location, " babel.config.js " ), str) ;
423
+ return ;
393
424
}
394
425
},
395
426
createTSConfig (location ) {
396
427
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 }` ;
428
+ 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 },` ;
429
+ str += ` \t "references": [\n `
430
+ str += ` \t\t {\n\t\t\t "path": "./tsconfig.vite-config.json"\n\t\t }\n\t ]\n }`
398
431
fs .writeFileSync (path .join (location, " tsconfig.json" ), str);
399
432
} else {
400
433
return ;
@@ -403,59 +436,39 @@ export default {
403
436
// create package.json file
404
437
createPackage (location ) {
405
438
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,` ;
439
+ str += ` \n\t "name": "My-OverVue-Project",` ;
440
+ str += ` \n\t "version": "0.0.0",` ;
409
441
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"` ;
442
+ str += ` \n\t\t "dev": "vite",` ;
443
+ if (this .exportAsTypescript === " on" ) {
444
+ str += ` \n\t\t "build": "vue-tsc --noEmit && vite build",` ;
445
+ str += ` \n\t\t "typecheck": "vue-tsc --noEmit",` ;
446
+ str += ` \n\t\t "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",` ;
447
+ } else {
448
+ str += ` \n\t\t "build": "vite build",` ;
449
+ str += ` \n\t\t "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore",` ;
450
+ }
451
+ str += ` \n\t\t "preview": "vite preview --port 5050"` ;
413
452
str += ` \n\t },` ;
414
453
str += ` \n\t "dependencies": {` ;
415
- str += ` \n\t\t "vue": "^3.2.26 ",` ;
454
+ str += ` \n\t\t "vue": "^3.2.31 ",` ;
416
455
str += ` \n\t\t "vue-router": "^4.0.12",` ;
417
456
str += ` \n\t\t "vuex": "^4.0.2"` ;
418
457
str += ` \n\t },` ;
419
458
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"` ;
459
+ str += ` \n\t\t "@vitejs/plugin-vue": "^2.2.2",` ;
460
+ str += ` \n\t\t "eslint": "^8.5.0",` ;
461
+ str += ` \n\t\t "eslint-plugin-vue": "^8.2.0",` ;
462
+ str += ` \n\t\t "vite": "^2.8.4"`
427
463
if (this .exportAsTypescript === " on" ) {
428
- str += ` ,\n\t\t "@vue/tsconfig": "^0.1.3",` ;
464
+ str += ` ,\n\t\t "@rushstack/eslint-patch": "^1.1.0",`
465
+ str += ` \n\t\t "@vue/tsconfig": "^0.1.3",` ;
429
466
str += ` \n\t\t "typescript": "~4.5.5",` ;
430
467
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?
468
+ str += ` \n\t\t "@types/node": "^16.11.25",` ;
469
+ str += ` \n\t\t "@vue/eslint-config-typescript": "^10.0.0"` ;
432
470
}
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 }` ;
471
+ str += ` \n\t }\n }` ;
459
472
fs .writeFileSync (path .join (location, " package.json" ), str);
460
473
},
461
474
exportFile (data ) {
@@ -468,12 +481,15 @@ export default {
468
481
fs .mkdirSync (path .join (data, " src" , " assets" ));
469
482
fs .mkdirSync (path .join (data, " src" , " components" ));
470
483
fs .mkdirSync (path .join (data, " src" , " views" ));
484
+ fs .mkdirSync (path .join (data, " src" , " router" ));
471
485
}
472
486
// creating basic boilerplate for vue app
473
487
this .createIndexFile (data);
474
488
this .createMainFile (data);
475
- this .createBabel (data);
489
+ this .createViteConfig (data);
490
+ this .createESLintRC (data);
476
491
this .createTSConfig (data);
492
+ this .createTSViteConfig (data);
477
493
this .createPackage (data);
478
494
// exports images to the /assets folder
479
495
// eslint-disable-next-line no-unused-vars
0 commit comments