Added @type alias, separated constants.ts file

This commit is contained in:
Dmitriy Shishkov 2021-07-15 20:05:30 +05:00
parent 74b3cc725d
commit 02453c8cf6
No known key found for this signature in database
GPG Key ID: 14358F96FCDD8060
10 changed files with 20 additions and 12 deletions

View File

@ -1,6 +1,6 @@
{
"scripts": {
"dev": "SNOWPACK_PUBLIC_API_URL=https://publitebackend.dmitriy.icu snowpack dev",
"dev": "SNOWPACK_PUBLIC_API_URL=https://publitebackend.dmitriy.icu SNOWPACK_PUBLIC_BASE_URL=http://localhost:8080 snowpack dev",
"build": "snowpack build",
"test": "echo \"Error: no test specified\" && exit 1"
},

View File

@ -21,7 +21,11 @@ module.exports = {
devOptions: {
open: "none",
},
alias: { "@assets": "./src/assets", "@utils": "./src/utils" },
alias: {
"@assets": "./src/assets",
"@utils": "./src/utils",
"@type": "./src/type",
},
exclude: ["**/node_modules/**/*", "**/*.test.*"],
env: {
// API_URL: "https://publitebackend.dmitriy.icu",

View File

@ -2,7 +2,7 @@ import React from "react";
import styles from "./BookItem.module.css";
import { IBook } from "../../types/book";
import { IBook } from "@type/book";
interface IBookItemProps extends IBook {}

View File

@ -1,9 +1,9 @@
import React, { useState } from "react";
import { IBook } from "../types/book";
import { IBook } from "@type/book";
import styles from "./Bookshelf.module.css";
import list from "../assets/bookList.json";
import list from "@assets/bookList.json";
import { BookItem } from "./BookItem";
import { AddBook } from "./AddBook";
@ -21,5 +21,3 @@ export const Bookshelf = () => {
</div>
);
};
export default Bookshelf;

View File

@ -1,6 +1,6 @@
import { IBook, optionalBookProps, requiredBookProps } from "./types/book";
import { IBook, optionalBookProps, requiredBookProps } from "@type/book";
const API_URL = import.meta.env.SNOWPACK_PUBLIC_API_URL;
import { API_URL } from "./constants";
export const validState = (file: File | undefined): file is File => {
if (!file) throw new Error("Book file is required. Please, attach one");

2
src/constants.ts Normal file
View File

@ -0,0 +1,2 @@
export const API_URL = import.meta.env.SNOWPACK_PUBLIC_API_URL;
export const BASE_URL = import.meta.env.SNOWPACK_PUBLIC_BASE_URL;

View File

@ -1,5 +1,5 @@
import { IBook } from "../types/book";
import { isArrOfStr } from "../types/utils";
import { IBook } from "@type/book";
import { isArrOfStr } from "@type/utils";
export const saveBook = (bookObj: IBook, key: string): void => {
const bookListStr = localStorage.getItem("list") || "[]";

View File

@ -10,6 +10,10 @@
"module": "ES2020",
"moduleResolution": "node",
"resolveJsonModule": true,
"paths": { "@assets/*": ["./src/assets/*"], "@utils/*": ["./src/utils/*"] }
"paths": {
"@assets/*": ["./src/assets/*"],
"@utils/*": ["./src/utils/*"],
"@type/*": ["./src/type/*"]
}
}
}