I am trying to learn nodejs, but am having a hell of a job trying to set up a new project to run with webpack, typescript, aurelia, nodejs, nodemon. Googling returns dozens of articles each with conflicting webpack.config.js setups.
What I’ve done so far:
au new --here
using all the defaults for the webpack and typescript options.
created the directory structure:
src
--- client/ (all the aurelia stuff goes in here)
--- server/
--- server/server.ts
--- server/controllers
--- server/controllers/welcome.controller.ts
I changed aurelia.json
"paths":{
"root":"src/client"
. ..
}
I changed webpack.config.js
to
const srcDir = path.resolve(__dirname, 'src/client');
I changed tsconfig.json
to:
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"sourceRoot": "client",
"sourceMap": true,
"allowJs": true,
"baseUrl": "client",
"skipLibCheck": true,
"lib": [
"es2017", "dom"
]
},
Running au run --watch
works fine, but of course it is only compiling the client stuff.
I’ve tried various scripts for `package.json’ such as:
"scripts": {
"watch-all": "npm run watch-server & npm run watch-client & nodemon --inspect private/src/server/server.js",
"watch-server": "tsc -p tsconfig.json -outDir private --watch",
"watch-client": "webpack --watch"
},
I can get the server to run at the terminal by typing nodemon --inspect private/src/server/server.js
, but that means that I have to use the scripts above which pollutes the directories with *.js
and *.map
files and also creates the private
directory.
I had to change the compilerOptions
in tsconfig.json
to module: commonjs
because running nodemon
fails with `unexpected token import { import * as express from “express”}
What I would like to do is to setup webpack so that when I type au run --watch
it also compiles the src/server
directory as well as src/client
and runs nodemon
on port: 3000 without cluttering up the directories with *.js
and *.map
files.
All help much appreciated.
Many thanks
Jeremy