diff --git a/.dockerignore b/.dockerignore index 7d245c9..fd51b21 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,5 @@ node_modules/ package-lock.json -build/ \ No newline at end of file +build/ +pnpm-lock.yaml +.vscode diff --git a/.gitignore b/.gitignore index 7d245c9..4b0bf20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules/ package-lock.json -build/ \ No newline at end of file +build/ +pnpm-lock.yaml +.vscode \ No newline at end of file diff --git a/package.json b/package.json index f76ed26..c6bcecc 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,25 @@ { + "private": true, "scripts": { - "dev": "SNOWPACK_PUBLIC_API_URL=http://localhost:8081 SNOWPACK_PUBLIC_BASE_URL=http://localhost:8080 snowpack dev", - "build": "snowpack build", - "test": "echo \"Error: no test specified\" && exit 1" + "build": "webpack --config ./webpack.config.prod.js", + "dev": "webpack serve --config ./webpack.config.dev.js --stats-error-details", + "test": "echo \"Error: no test specified\" && exit 1", + "h": "cat ./webpack.config.dev.js" }, "devDependencies": { - "@snowpack/plugin-typescript": "^1.2.1", - "@types/node": "^16.3.3", - "@types/react": "^17.0.14", + "@svgr/webpack": "^5.5.0", + "@types/react": "^17.0.15", "@types/react-dom": "^17.0.9", - "@types/snowpack-env": "^2.3.3", - "snowpack": "^3.8.0", - "snowpack-plugin-svgr": "^0.1.2", - "typescript": "^4.3.5" + "copy-webpack-plugin": "^9.0.1", + "css-loader": "^6.2.0", + "esbuild-loader": "^2.13.1", + "fork-ts-checker-webpack-plugin": "^6.2.13", + "style-loader": "^3.2.1", + "typescript": "^4.3.5", + "typescript-plugin-css-modules": "^3.4.0", + "webpack": "^5.46.0", + "webpack-cli": "^4.7.2", + "webpack-dev-server": "^3.11.2" }, "dependencies": { "react": "^17.0.2", diff --git a/public/index.html b/public/index.html index 1df4b4e..9fbc3d2 100644 --- a/public/index.html +++ b/public/index.html @@ -9,6 +9,6 @@
- + diff --git a/snowpack.config.js b/snowpack.config.js deleted file mode 100644 index abe1a45..0000000 --- a/snowpack.config.js +++ /dev/null @@ -1,28 +0,0 @@ -// Snowpack Configuration File -// See all supported options: https://www.snowpack.dev/reference/configuration - -/** @type {import("snowpack").SnowpackUserConfig } */ -module.exports = { - plugins: ["@snowpack/plugin-typescript", "snowpack-plugin-svgr"], - packageOptions: { - polyfillNode: true, - }, - mount: { - public: "/", - src: "/dist", - }, - optimize: { - // bundle: true, - }, - routes: [ - { match: "routes", src: "robots.txt", dest: "/robots.txt" }, - { match: "routes", src: ".*", dest: "/index.html" }, - ], - devOptions: { - open: "none", - }, - alias: { - "~": "./src", - }, - exclude: ["**/node_modules/**/*", "**/*.test.*"], -}; diff --git a/src/constants.ts b/src/constants.ts index f62fdca..7473c9b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,2 +1,3 @@ -export const API_URL = import.meta.env.SNOWPACK_PUBLIC_API_URL; -export const BASE_URL = import.meta.env.SNOWPACK_PUBLIC_BASE_URL; +export const API_URL = process.env.PUBLIC_API_URL; +// export const BASE_URL = process.env.PUBLIC_BASE_URL; +export const CACHE = "v1"; diff --git a/src/index.tsx b/src/index.tsx index 78f3909..d03f655 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -12,6 +12,3 @@ ReactDOM.render( document.getElementById("root") ); -if (import.meta.hot) { - import.meta.hot.accept(); -} diff --git a/src/utils/api.ts b/src/utils/api.ts index 13f6fde..7a028b1 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -43,7 +43,7 @@ export const validateResponse = (content: unknown): content is BookT => { if (content && typeof content === "object") for (const key of requiredBookProps) if (!(key in content)) { - if (import.meta.env.NODE_ENV === "development") + if (process.env.NODE_ENV === "development") console.log(`${key} is not specified in server response`); return false; } diff --git a/tsconfig.json b/tsconfig.json index 4c356d1..a4ea4a9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,18 @@ { "compilerOptions": { - "target": "es6", - "strict": true, "esModuleInterop": true, - "skipLibCheck": true, + "isolatedModules": true, "forceConsistentCasingInFileNames": true, "jsx": "react-jsx", - "lib": ["DOM"], + "lib": ["DOM", "webworker"], "module": "ES2020", "moduleResolution": "node", - "resolveJsonModule": true, "paths": { "~/*": ["./src/*"] - } + }, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "target": "es6" } } diff --git a/webpack.config.common.js b/webpack.config.common.js new file mode 100644 index 0000000..9682847 --- /dev/null +++ b/webpack.config.common.js @@ -0,0 +1,53 @@ +const path = require("path"); +const webpack = require("webpack"); + +const CopyPlugin = require("copy-webpack-plugin"); +const ForkTsCheckerPlugin = require("fork-ts-checker-webpack-plugin"); + +module.exports = { + entry: { + "index.js": "./src/index.tsx", + "sw.js": "./src/serviceWorker/index.ts", + }, + output: { + path: path.resolve(__dirname, `./build/`), + clean: true, + filename: "[name]", + }, + module: { + rules: [ + { + test: /\.tsx?$/, + loader: "esbuild-loader", + options: { + loader: "tsx", + target: "es2015", + }, + exclude: /node_modules/, + }, + { + test: /\.css$/, + use: ["style-loader", "css-loader"], + }, + { + test: /\.svg$/, + use: ["@svgr/webpack"], + }, + ], + }, + resolve: { + extensions: [".ts", ".tsx", ".js", ".json"], + alias: { "~": path.resolve(__dirname, "src/") }, + }, + plugins: [ + new webpack.DefinePlugin({ + "process.env.PUBLIC_API_URL": JSON.stringify( + "https://publitebackend.dmitriy.icu" + ), + }), + new ForkTsCheckerPlugin(), + new CopyPlugin({ + patterns: [{ from: "./public", to: "." }], + }), + ], +}; diff --git a/webpack.config.dev.js b/webpack.config.dev.js new file mode 100644 index 0000000..d8fee98 --- /dev/null +++ b/webpack.config.dev.js @@ -0,0 +1,22 @@ +const path = require("path"); +const webpack = require("webpack"); + +const webpackConfig = require("./webpack.config.common"); + +module.exports = { + ...webpackConfig, + mode: "development", + watchOptions: { ignored: /node_modules/ }, + devServer: { + contentBase: path.join(__dirname, "build"), + compress: true, + port: 8080, + hot: true, + }, + plugins: [ + new webpack.DefinePlugin({ + "process.env.NODE_ENV": JSON.stringify("development"), + }), + ...webpackConfig.plugins, + ], +}; diff --git a/webpack.config.prod.js b/webpack.config.prod.js new file mode 100644 index 0000000..5b56988 --- /dev/null +++ b/webpack.config.prod.js @@ -0,0 +1,18 @@ +const { ESBuildMinifyPlugin } = require("esbuild-loader"); +const webpack = require("webpack"); + +const webpackConfig = require("./webpack.config.common"); + +module.exports = { + ...webpackConfig, + optimization: { + minimizer: [new ESBuildMinifyPlugin()], + }, + mode: "production", + plugins: [ + new webpack.DefinePlugin({ + "process.env.NODE_ENV": JSON.stringify("production"), + }), + ...webpackConfig.plugins, + ], +};