diff --git a/package-lock.json b/package-lock.json index 733bc82..022ea93 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@aleleba/create-react-ssr", - "version": "2.0.1", + "version": "2.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@aleleba/create-react-ssr", - "version": "2.0.1", + "version": "2.0.3", "license": "MIT", "dependencies": { "@babel/register": "^7.17.7", diff --git a/package.json b/package.json index 780fcca..75713cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aleleba/create-react-ssr", - "version": "2.0.3", + "version": "2.0.4", "description": "Starter Kit of server side render of react", "bin": "./bin/cli.js", "main": "src/server/index", diff --git a/src/server/getHashManifest.js b/src/server/getHashManifest.ts similarity index 81% rename from src/server/getHashManifest.js rename to src/server/getHashManifest.ts index 6f9a54a..6c92ac3 100644 --- a/src/server/getHashManifest.js +++ b/src/server/getHashManifest.ts @@ -4,7 +4,7 @@ const getHashManifest = () => { try { const baseUrl = __dirname.replace(/\/server(.*)/,''); const fullURL = `${baseUrl}/assets/manifest-hash.json` ; - return JSON.parse(fs.readFileSync(fullURL)); + return JSON.parse(fs.readFileSync(fullURL).toString()); }catch(err){ console.error(err); } diff --git a/src/server/index.js b/src/server/index.ts similarity index 93% rename from src/server/index.js rename to src/server/index.ts index cde49ea..1e431af 100644 --- a/src/server/index.js +++ b/src/server/index.ts @@ -2,8 +2,6 @@ require('dotenv').config(); require('ignore-styles'); -//require('webpack-node-externals')(); - require('@babel/register')({ 'presets': [ ['@babel/preset-env', {'targets': {'node': 'current'}}], diff --git a/tsconfig.json b/tsconfig.json index 5dbc489..3261e01 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,11 +15,11 @@ "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, - "isolatedModules": true, "noEmit": false, "jsx": "react-jsx", "experimentalDecorators": true, "esModuleInterop": true, + "isolatedModules": false, "types": [ "react/next", "react-dom/next", diff --git a/webpack.config.dev.server.js b/webpack.config.dev.server.js index fdac288..c696877 100644 --- a/webpack.config.dev.server.js +++ b/webpack.config.dev.server.js @@ -14,7 +14,7 @@ module.exports = { mode: 'development', name: 'server', entry: { - server: `${ROOT_DIR}/src/server/index.js`, + server: `${ROOT_DIR}/src/server/index.ts`, }, resolve: { extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'], diff --git a/webpack.config.js b/webpack.config.js index 601d550..6f9dfeb 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -9,16 +9,19 @@ const { WebpackManifestPlugin } = require('webpack-manifest-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const ESLintPlugin = require('eslint-webpack-plugin'); const CopyPlugin = require('copy-webpack-plugin'); +const ROOT_DIR = path.resolve(__dirname); +const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args); +const BUILD_DIR = resolvePath('build'); const { InjectManifest } = require('workbox-webpack-plugin'); const nodeExternals = require('webpack-node-externals'); const PUBLIC_URL = process.env.PUBLIC_URL || '/'; const frontendConfig = { entry: { - frontend: './src/frontend/index.tsx', + frontend: `${ROOT_DIR}/src/frontend/index.tsx`, }, output: { - path: path.resolve(__dirname, 'build'), + path: BUILD_DIR, filename: 'assets/app-[name]-[fullhash].js', publicPath: PUBLIC_URL, }, @@ -89,16 +92,16 @@ const frontendConfig = { new CopyPlugin({ patterns: [ { - from: './public/manifest.json', to: '', + from: `${ROOT_DIR}/public/manifest.json`, to: '', }, { - from: './public/favicon.ico', to: '', + from: `${ROOT_DIR}/public/favicon.ico`, to: '', }, { - from: './public/logo192.png', to: '', + from: `${ROOT_DIR}/public/logo192.png`, to: '', }, { - from: './public/logo512.png', to: '', + from: `${ROOT_DIR}/public/logo512.png`, to: '', }, ] }), @@ -135,7 +138,7 @@ const frontendConfig = { const serverConfig = { entry: { - server: './src/server/index.js', + server: './src/server/index.ts', }, target: "node", externals: [nodeExternals()], @@ -234,4 +237,4 @@ const serverConfig = { }, }; - module.exports = [frontendConfig, serverConfig]; +module.exports = [frontendConfig, serverConfig];