Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
Fix deploys (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Mar 3, 2020
1 parent 9359a43 commit a166753
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: http-server dist --proxy http://127.0.0.1:$PORT?
web: npm run start
7 changes: 4 additions & 3 deletions client/webpack/common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// helpers
const { resolvePath } = require("./tools/helpers");
const babelLoaderOptions = require("./tools/babel-loader-options");
const path = require("path");
const paths = require("./tools/paths");
const resolveAlias = require("./tools/resolve-alias");

Expand All @@ -12,16 +13,16 @@ const configForkTsCheckerWebpackPlugin = {
useTypescriptIncrementalApi: true
};

const root = path.resolve(__dirname, "..");
const mode = process.env.NODE_ENV;
const devMode = mode === "development" ? true : false;

module.exports = {
context: resolvePath(paths.source),
entry: {
main: "./index.tsx"
main: path.join(root, "src", "index.tsx")
},
output: {
path: resolvePath(paths.dist)
path: path.join(root, "..", "server", "dist", "public")
},
node: {
fs: "empty"
Expand Down
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
{
"scripts": {
"client:build": "(cd client && npm run build)",
"server:build": "(cd server && npm run build)",
"server:start": "(cd server && npm run start)",
"client:build": "./package.sh client run build",
"client:install": "./package.sh client install",

"server:build": "./package.sh server run build",
"server:start": "./package.sh server run start",
"server:install": "./package.sh server install",

"program:build": "./program/do.sh build",
"program:clean": "./program/do.sh clean"
"program:clean": "./program/do.sh clean",

"start": "npm run server:start",
"build": "./package.sh both run build",
"lint": "./package.sh both run lint",
"format": "./package.sh both run format",
"preinstall": "./package.sh both install"
}
}
12 changes: 12 additions & 0 deletions package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

dir="$1"
shift
if [ "$dir" = "both" ]; then
set -ex
(cd client && npm "$@" )
(cd server && npm "$@" )
else
set -ex
(cd $dir && npm "$@" )
fi
3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"scripts": {
"build": "webpack --mode production",
"start": "node dist/server.js",
"start": "node ./dist/server.js",
"start:dev": "PUBLIC_PATH=../dist/public ts-node src/index.ts",
"build:dev": "webpack --mode development",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"lint": "set -ex; eslint --ext .js,.ts,.tsx .",
Expand Down
7 changes: 6 additions & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const port = process.env.PORT || 8080;
const app = express();
app.use(cors());
app.use(express.json()); // for parsing application/json
app.use(express.static(path.join(__dirname, "../../client/dist")));

const publicPath = process.env.PUBLIC_PATH || "public";
const staticPath = path.join(__dirname, publicPath);
app.use("/", express.static(staticPath));
console.log(`Serving static files from: ${staticPath}`);

app.listen(port);
console.log(`Server listening on port: ${port}`);
3 changes: 3 additions & 0 deletions server/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module.exports = (env, argv) => {
mode,
target: "node",
entry: ["./src/index.ts"],
node: {
__dirname: false
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "server.js"
Expand Down

0 comments on commit a166753

Please sign in to comment.