Changing some files to typescript and fixing webpack build.

This commit is contained in:
Alejandro Lembke Barrientos 2022-05-23 21:14:30 +00:00
parent 1c5117f6d4
commit 0645d471bb
7 changed files with 17 additions and 16 deletions

4
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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);
}

View File

@ -2,8 +2,6 @@ require('dotenv').config();
require('ignore-styles');
//require('webpack-node-externals')();
require('@babel/register')({
'presets': [
['@babel/preset-env', {'targets': {'node': 'current'}}],

View File

@ -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",

View File

@ -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'],

View File

@ -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];