diff --git a/.gitignore b/.gitignore index 136769a..226d09c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /node_modules package-lock.json npm-debug* -/build /dist +/public .idea +.vscode diff --git a/app/tsconfig.json b/app/tsconfig.json index ebb7f6e..9f087ba 100644 --- a/app/tsconfig.json +++ b/app/tsconfig.json @@ -8,9 +8,9 @@ "es6", "dom" ], - // "typeRoots": ["node_modules/@types"], "types": [ - "webpack-env" + "webpack-env", + "node" ], "strict": true, "baseUrl": ".", @@ -22,8 +22,5 @@ "./*" ] } - }, - "files": [ - "./app/script/index.tsx" - ] + } } \ No newline at end of file diff --git a/webpack/base.config.js b/app/webpack/base.config.js similarity index 91% rename from webpack/base.config.js rename to app/webpack/base.config.js index 4fc8ce4..51941d6 100644 --- a/webpack/base.config.js +++ b/app/webpack/base.config.js @@ -2,7 +2,7 @@ const path = require("path"); const webpack = require("webpack"); const HtmlWebpackPlugin = require("html-webpack-plugin"); -const rootDir = path.resolve(__dirname, ".."); +const rootDir = path.resolve(__dirname, "..", ".."); module.exports = { entry: [ @@ -10,7 +10,7 @@ module.exports = { "./app/index.tsx" ], output: { - path: path.resolve(rootDir, "build"), + path: path.resolve(rootDir, "public"), filename: "bundle.js" }, resolve: { diff --git a/app/webpack/config.js b/app/webpack/config.js new file mode 100644 index 0000000..ff2bc41 --- /dev/null +++ b/app/webpack/config.js @@ -0,0 +1,5 @@ +const isProduction = process.env.NODE_ENV === "production"; + +module.exports = require( + isProduction ? "./prod.config.js" : "./dev.config.js" +); diff --git a/webpack/dev.config.js b/app/webpack/dev.config.js similarity index 100% rename from webpack/dev.config.js rename to app/webpack/dev.config.js diff --git a/webpack/prod.config.js b/app/webpack/prod.config.js similarity index 100% rename from webpack/prod.config.js rename to app/webpack/prod.config.js diff --git a/package.json b/package.json index feb9fa8..df9cae2 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,12 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "clean": "rm -rf ./dist ./build", - "build": "webpack --config ./webpack/prod.config.js", - "start": "webpack-dev-server --config ./webpack/dev.config.js", + "build:app": "webpack --config ./app/webpack/prod.config.js", + "build:server": "tsc --project server", + "watch:app": "yarn build:app --watch", + "watch:server": "yarn build:server --watch", + "start:dev-server": "webpack-dev-server --config ./app/webpack/dev.config.js", + "start": "node dist/index.js", "lint": "tslint --project . --force" }, "repository": { @@ -23,6 +27,7 @@ "dependencies": { "@types/classnames": "^2.2.0", "@types/core-js": "^0.9.42", + "@types/express": "^4.0.37", "@types/node": "^8.0.6", "@types/object-assign": "^4.0.30", "@types/paho-mqtt": "^1.0.0", @@ -33,6 +38,7 @@ "@types/react-transition-group": "^1.1.1", "classnames": "^2.2.5", "core-js": "^2.4.1", + "express": "^4.15.4", "font-awesome": "^4.7.0", "mobx": "^3.1.11", "mobx-react": "^4.2.1", @@ -47,6 +53,7 @@ "webpack-merge": "^4.1.0" }, "devDependencies": { + "@types/webpack-dev-middleware": "^1.9.3", "@types/webpack-env": "^1.13.0", "awesome-typescript-loader": "^3.1.3", "css-loader": "^0.28.4", @@ -61,6 +68,7 @@ "tslint-react": "^3.2.0", "typescript": "^2.3.4", "webpack": "^3.0.0", + "webpack-dev-middleware": "^1.12.0", "webpack-dev-server": "^2.4.4" } } diff --git a/server/app/index.ts b/server/app/index.ts new file mode 100644 index 0000000..6a648f7 --- /dev/null +++ b/server/app/index.ts @@ -0,0 +1,9 @@ +import * as express from "express"; + +import serveApp from "./serveApp"; + +const app = express(); + +app.use(serveApp()); + +export default app; diff --git a/server/app/serveApp.ts b/server/app/serveApp.ts new file mode 100644 index 0000000..0ca0722 --- /dev/null +++ b/server/app/serveApp.ts @@ -0,0 +1,11 @@ +import * as webpack from "webpack"; +import * as webpackMiddleware from "webpack-dev-middleware"; + +/* tslint:disable-next-line:no-var-requires */ +const webpackConfig = require("../../app/webpack/config.js"); + +export default function serveApp() { + return webpackMiddleware( + webpack(webpackConfig), + ); +} diff --git a/server/index.ts b/server/index.ts new file mode 100644 index 0000000..923e3ce --- /dev/null +++ b/server/index.ts @@ -0,0 +1,9 @@ + +import app from "./app"; + + +const port = +(process.env.PORT || 8080); +const host = process.env.HOST || "0.0.0.0"; +app.listen(port, host, () => { + console.log(`listening at ${host}:${port}`); +}); diff --git a/server/tsconfig.json b/server/tsconfig.json new file mode 100644 index 0000000..de6c9e4 --- /dev/null +++ b/server/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "outDir": "../dist", + "sourceMap": true, + "experimentalDecorators": true, + "target": "es5", + "lib": [ + "es6", + "dom" + ], + "types": [ + "webpack-env", + "node" + ], + "strict": true + }, + "files": [ + "./index.ts" + ] +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 5d7eabb..f06bea0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6,10 +6,37 @@ version "2.2.3" resolved "https://registry.yarnpkg.com/@types/classnames/-/classnames-2.2.3.tgz#3f0ff6873da793870e20a260cada55982f38a9e5" +"@types/connect@*": + version "3.4.31" + resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.31.tgz#1f92d6b117ecc05076c49ecd024f7976e528bad9" + dependencies: + "@types/node" "*" + "@types/core-js@^0.9.42": version "0.9.43" resolved "https://registry.yarnpkg.com/@types/core-js/-/core-js-0.9.43.tgz#65d646c5e8c0cd1bdee37065799f9d3d48748253" +"@types/express-serve-static-core@*": + version "4.0.50" + resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.0.50.tgz#c5a139b5d29d2305aae6d982f69cef36120beacf" + dependencies: + "@types/node" "*" + +"@types/express@^4.0.37": + version "4.0.37" + resolved "https://registry.yarnpkg.com/@types/express/-/express-4.0.37.tgz#625ac3765169676e01897ca47011c26375784971" + dependencies: + "@types/express-serve-static-core" "*" + "@types/serve-static" "*" + +"@types/mime@*": + version "1.3.1" + resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.1.tgz#2cf42972d0931c1060c7d5fa6627fce6bd876f2f" + +"@types/node@*": + version "8.0.27" + resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.27.tgz#13fbe7e92afeecebb843d7cea6c15b521e0000e1" + "@types/node@^8.0.6": version "8.0.25" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.25.tgz#66ecaf4df93f5281b48427ee96fbcdfc4f0cdce1" @@ -50,10 +77,46 @@ version "16.0.5" resolved "https://registry.yarnpkg.com/@types/react/-/react-16.0.5.tgz#d713cf67cc211dea20463d2a0b66005c22070c4b" +"@types/serve-static@*": + version "1.7.32" + resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.7.32.tgz#0f6732e4dab0813771dd8fc8fe14940f34728b4c" + dependencies: + "@types/express-serve-static-core" "*" + "@types/mime" "*" + +"@types/source-map@*": + version "0.5.1" + resolved "https://registry.yarnpkg.com/@types/source-map/-/source-map-0.5.1.tgz#7e74db5d06ab373a712356eebfaea2fad0ea2367" + +"@types/tapable@*": + version "0.2.4" + resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-0.2.4.tgz#8181a228da46185439300e600c5ae3b3b3982585" + +"@types/uglify-js@*": + version "2.6.29" + resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-2.6.29.tgz#521347f69e20201d218f5991ae66e10878afcf1a" + dependencies: + "@types/source-map" "*" + +"@types/webpack-dev-middleware@^1.9.3": + version "1.9.3" + resolved "https://registry.yarnpkg.com/@types/webpack-dev-middleware/-/webpack-dev-middleware-1.9.3.tgz#2120f79a4fbb0dc49ddba97e4b0b778f947c7c5b" + dependencies: + "@types/connect" "*" + "@types/webpack" "*" + "@types/webpack-env@^1.13.0": version "1.13.0" resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.0.tgz#3044381647e11ee973c5af2e925323930f691d80" +"@types/webpack@*": + version "3.0.10" + resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-3.0.10.tgz#1d27db07df32109f8c882535b547aae4252fd53e" + dependencies: + "@types/node" "*" + "@types/tapable" "*" + "@types/uglify-js" "*" + abbrev@1: version "1.1.0" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f" @@ -1423,7 +1486,7 @@ expand-range@^1.8.1: dependencies: fill-range "^2.1.0" -express@^4.13.3: +express@^4.13.3, express@^4.15.4: version "4.15.4" resolved "https://registry.yarnpkg.com/express/-/express-4.15.4.tgz#032e2253489cf8fce02666beca3d11ed7a2daed1" dependencies: @@ -4492,7 +4555,7 @@ wbuf@^1.1.0, wbuf@^1.7.2: dependencies: minimalistic-assert "^1.0.0" -webpack-dev-middleware@^1.11.0: +webpack-dev-middleware@^1.11.0, webpack-dev-middleware@^1.12.0: version "1.12.0" resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-1.12.0.tgz#d34efefb2edda7e1d3b5dbe07289513219651709" dependencies: