From 6cd53a93d3d39540f3c127a7a67da158ac1f54aa Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 16:49:37 -0400 Subject: [PATCH 01/11] feat: adds types to Nuxt config --- template/nuxt.config.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index e10b5f256..770ef91a8 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -2,13 +2,14 @@ // See: https://nuxtjs.org/guide/configuration/ import path from 'path' +import { Configuration } from '@nuxt/types' import pkg from './package.json' const envPath = path.resolve(__dirname, 'config', '.env') require('dotenv').config({ 'path': envPath }) -module.exports = { +const config: Configuration = { /** * Headers of the page. */ @@ -104,10 +105,12 @@ module.exports = { */ 'build': { extend (config, { isDev, isClient }): void { - // This line allows us to use `@import "~/scss/..."` in our app: - config.resolve.alias['/scss'] = path.resolve(__dirname, 'client', 'scss') + if (config.resolve && config.resolve.alias) { + // This line allows us to use `@import "~/scss/..."` in our app: + config.resolve.alias['/scss'] = path.resolve(__dirname, 'client', 'scss') + } - if (isDev && isClient) { + if (isDev && isClient && config.module) { // Enabling eslint: config.module.rules.push({ 'enforce': 'pre', @@ -116,11 +119,15 @@ module.exports = { 'exclude': /(node_modules)/u, }) - // Enabling stylelint: - config.plugins.push(require('stylelint-webpack-plugin')({ - 'files': 'client/**/*.{vue,scss,css}', - })) + if (config.plugins) { + // Enabling stylelint: + config.plugins.push(require('stylelint-webpack-plugin')({ + 'files': 'client/**/*.{vue,scss,css}', + })) + } } }, }, } + +export default config \ No newline at end of file From c492046b91b56dc9be0350f69a1dfdaf01a4c6c4 Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 12:13:22 -0400 Subject: [PATCH 02/11] fix: @nuxt/types import should occur before path --- template/nuxt.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index 770ef91a8..74f44dd1e 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -1,8 +1,8 @@ // This is Nuxt configuration file // See: https://nuxtjs.org/guide/configuration/ -import path from 'path' import { Configuration } from '@nuxt/types' +import path from 'path' import pkg from './package.json' From afdea736c2958ce3c38fda74b425f2663a760b42 Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 12:15:05 -0400 Subject: [PATCH 03/11] fix: removes unnecessary return type --- template/nuxt.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index 74f44dd1e..f0fcd190e 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -104,7 +104,7 @@ const config: Configuration = { * Build configuration. */ 'build': { - extend (config, { isDev, isClient }): void { + extend (config, { isDev, isClient }) { if (config.resolve && config.resolve.alias) { // This line allows us to use `@import "~/scss/..."` in our app: config.resolve.alias['/scss'] = path.resolve(__dirname, 'client', 'scss') From 2baa00acada149617828a85c286f6ffc31c32196 Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 12:15:21 -0400 Subject: [PATCH 04/11] fix: config is already declared in the upper scope --- template/nuxt.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index f0fcd190e..6c37f60b0 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -9,7 +9,7 @@ import pkg from './package.json' const envPath = path.resolve(__dirname, 'config', '.env') require('dotenv').config({ 'path': envPath }) -const config: Configuration = { +const nuxtConfig: Configuration = { /** * Headers of the page. */ @@ -130,4 +130,4 @@ const config: Configuration = { }, } -export default config \ No newline at end of file +export default nuxtConfig \ No newline at end of file From 311e9dd6d2f62d8b7cd085538a7f3f7edd30b483 Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 12:18:23 -0400 Subject: [PATCH 05/11] fix: line 110 exceeds the max line length of 80 --- template/nuxt.config.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index 6c37f60b0..c95d9f7ed 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -9,6 +9,10 @@ import pkg from './package.json' const envPath = path.resolve(__dirname, 'config', '.env') require('dotenv').config({ 'path': envPath }) +const ROOT_DIR_PATH: Configuration['rootDir'] = path.resolve(__dirname) +const SRC_DIR: Configuration['srcDir'] = 'client' +const SCSS_PATH = path.resolve(ROOT_DIR_PATH, SRC_DIR, 'scss') + const nuxtConfig: Configuration = { /** * Headers of the page. @@ -47,8 +51,8 @@ const nuxtConfig: Configuration = { /** * Specify Nuxt source directory. */ - 'srcDir': 'client', - 'rootDir': path.resolve(__dirname), + 'srcDir': SRC_DIR, + 'rootDir': ROOT_DIR_PATH, /** * Modules that are used in build-time only. @@ -107,7 +111,7 @@ const nuxtConfig: Configuration = { extend (config, { isDev, isClient }) { if (config.resolve && config.resolve.alias) { // This line allows us to use `@import "~/scss/..."` in our app: - config.resolve.alias['/scss'] = path.resolve(__dirname, 'client', 'scss') + config.resolve.alias['/scss'] = SCSS_PATH } if (isDev && isClient && config.module) { From 2ecebe33c47b3fb0ad1cdc67ba4f564d5ad9e030 Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 12:18:45 -0400 Subject: [PATCH 06/11] fix: newline required at end of file but not foun --- template/nuxt.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index c95d9f7ed..2d7f6f324 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -134,4 +134,4 @@ const nuxtConfig: Configuration = { }, } -export default nuxtConfig \ No newline at end of file +export default nuxtConfig From 568351b3be94b9cf48540f3f53fba01fb53092e4 Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 12:28:17 -0400 Subject: [PATCH 07/11] fix: missing return type on function --- template/nuxt.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index 2d7f6f324..135ee7fb6 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -108,7 +108,7 @@ const nuxtConfig: Configuration = { * Build configuration. */ 'build': { - extend (config, { isDev, isClient }) { + extend (config, { isDev, isClient }): void { if (config.resolve && config.resolve.alias) { // This line allows us to use `@import "~/scss/..."` in our app: config.resolve.alias['/scss'] = SCSS_PATH From bda4d100c760a89c10b01c5d2dcddc47025e0dda Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 13:36:05 -0400 Subject: [PATCH 08/11] fix: standardizes naming --- template/nuxt.config.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index 135ee7fb6..16ac5acc4 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -9,9 +9,9 @@ import pkg from './package.json' const envPath = path.resolve(__dirname, 'config', '.env') require('dotenv').config({ 'path': envPath }) -const ROOT_DIR_PATH: Configuration['rootDir'] = path.resolve(__dirname) +const ROOT_DIR: Configuration['rootDir'] = path.resolve(__dirname) const SRC_DIR: Configuration['srcDir'] = 'client' -const SCSS_PATH = path.resolve(ROOT_DIR_PATH, SRC_DIR, 'scss') +const SCSS_DIR = path.resolve(ROOT_DIR, SRC_DIR, 'scss') const nuxtConfig: Configuration = { /** @@ -52,7 +52,7 @@ const nuxtConfig: Configuration = { * Specify Nuxt source directory. */ 'srcDir': SRC_DIR, - 'rootDir': ROOT_DIR_PATH, + 'rootDir': ROOT_DIR, /** * Modules that are used in build-time only. @@ -111,7 +111,7 @@ const nuxtConfig: Configuration = { extend (config, { isDev, isClient }): void { if (config.resolve && config.resolve.alias) { // This line allows us to use `@import "~/scss/..."` in our app: - config.resolve.alias['/scss'] = SCSS_PATH + config.resolve.alias['/scss'] = SCSS_DIR } if (isDev && isClient && config.module) { From fcf53c019ed17d8058d791610c1468eebbb0ba0a Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 13:39:57 -0400 Subject: [PATCH 09/11] refactor: imports resolve function --- template/nuxt.config.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index 16ac5acc4..609587007 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -2,16 +2,16 @@ // See: https://nuxtjs.org/guide/configuration/ import { Configuration } from '@nuxt/types' -import path from 'path' +import { resolve } from 'path' import pkg from './package.json' -const envPath = path.resolve(__dirname, 'config', '.env') +const envPath = resolve(__dirname, 'config', '.env') require('dotenv').config({ 'path': envPath }) -const ROOT_DIR: Configuration['rootDir'] = path.resolve(__dirname) +const ROOT_DIR: Configuration['rootDir'] = resolve(__dirname) const SRC_DIR: Configuration['srcDir'] = 'client' -const SCSS_DIR = path.resolve(ROOT_DIR, SRC_DIR, 'scss') +const SCSS_DIR = resolve(ROOT_DIR, SRC_DIR, 'scss') const nuxtConfig: Configuration = { /** From 36ec5f2099ea748cb783e07d6f4506293c22faa2 Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 16:52:37 -0400 Subject: [PATCH 10/11] feat: refactors dotenv to use types --- template/nuxt.config.ts | 7 ++++--- template/package-lock.json | 9 +++++++++ template/package.json | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index 609587007..275bd2000 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -2,16 +2,17 @@ // See: https://nuxtjs.org/guide/configuration/ import { Configuration } from '@nuxt/types' +import { config as dotenv } from 'dotenv' import { resolve } from 'path' import pkg from './package.json' -const envPath = resolve(__dirname, 'config', '.env') -require('dotenv').config({ 'path': envPath }) - const ROOT_DIR: Configuration['rootDir'] = resolve(__dirname) const SRC_DIR: Configuration['srcDir'] = 'client' const SCSS_DIR = resolve(ROOT_DIR, SRC_DIR, 'scss') +const ENV_PATH = resolve(ROOT_DIR, 'config', '.env') + +dotenv({ 'path': ENV_PATH }) const nuxtConfig: Configuration = { /** diff --git a/template/package-lock.json b/template/package-lock.json index 6bfe01bd0..4041d57c2 100644 --- a/template/package-lock.json +++ b/template/package-lock.json @@ -2571,6 +2571,15 @@ "@types/node": "*" } }, + "@types/dotenv": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/@types/dotenv/-/dotenv-6.1.1.tgz", + "integrity": "sha512-ftQl3DtBvqHl9L16tpqqzA4YzCSXZfi7g8cQceTz5rOlYtk/IZbFjAv3mLOQlNIgOaylCQWQoBdDQHPgEBJPHg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", diff --git a/template/package.json b/template/package.json index afc32c485..4a5c7abf3 100644 --- a/template/package.json +++ b/template/package.json @@ -59,6 +59,7 @@ "devDependencies": { "@nuxt/typescript-build": "^0.3.0", "@nuxt/vue-app": "^2.10.0", + "@types/dotenv": "6.1.1", "@types/faker": "^4.1.6", "@types/jest": "^24.0.18", "@types/rosie": "0.0.36", From 87d2949292c30a38c42982d55986e181c1ed0b91 Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Mon, 7 Oct 2019 16:53:47 -0400 Subject: [PATCH 11/11] style: disables complexity check on the config --- template/nuxt.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/template/nuxt.config.ts b/template/nuxt.config.ts index 275bd2000..d8f944a74 100644 --- a/template/nuxt.config.ts +++ b/template/nuxt.config.ts @@ -109,6 +109,7 @@ const nuxtConfig: Configuration = { * Build configuration. */ 'build': { + // eslint-disable-next-line complexity extend (config, { isDev, isClient }): void { if (config.resolve && config.resolve.alias) { // This line allows us to use `@import "~/scss/..."` in our app: