- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- ソース を表示
- TypeScript/バックエンド/TS + ExpressでHelloWorld へ行く。
- 1 (2019-04-23 (火) 14:24:47)
- 2 (2019-04-23 (火) 16:50:40)
NPM package.json初期化
npm init -y
Webpack インストール
npm install -D webpack webpack-cli '@webpack-cli/init' npm install -D webpack-node-externals npm install -D rimraf mkdirp
vim webpack.config.js
-----
const path = require('path');
module.exports = {
target: 'node',
mode: 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
},
resolve: {
extensions: ['.js']
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
};
-----
TypeScirpt インストール
npm add -D typescript ts-node @types/node core-js ts-loader
npx tsc --init
vim webpack.config.js
-----
module: {
rules: [
+ {
+ test: /\.tsx?$/,
+ use: 'ts-loader',
+ exclude: /node_modules/
+ },
resolve: {
+ extensions: ['.ts', '.js']
},
-----
Express.js インストール
npm install express npm install -D '@types/express'
Git リポジトリ初期化
vim .gitignore ----- node_modules/ package-lock.json ----- git init git add . git commit -m 'Initial commit'
Express.js アプリケーション作成
vim package.json
"scripts": {
- "build": "rimraf ./dist && mkdirp ./dist && npx webpack",
- "start": "node ./dist/bundle.js",
"test": "echo \"Error: no test specified\" && exit 1" },