Initial commit
This commit is contained in:
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@@ -0,0 +1,8 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = false
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
dist/
|
||||
node_modules/
|
||||
yarn.lock
|
||||
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "启动程序",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}/dist/binary.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# NodeJS 起始项目
|
||||
|
||||
搭建好 TypeScript NodeJS 的空项目,提供编译、调试流程,内置 tiny 使用代码库。
|
||||
18
package.json
Normal file
18
package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "tiny-nodejs-starter-kit",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"dev": "node_modules/.bin/webpack --config webpack.config.js --watch",
|
||||
"compile": "node_modules/.bin/webpack --config webpack.config.js --env.production"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.0.1",
|
||||
"ts-loader": "^7.0.4",
|
||||
"tsconfig-paths-webpack-plugin": "^3.2.0",
|
||||
"typescript": "^3.9.2",
|
||||
"webpack": "^4.43.0",
|
||||
"webpack-cli": "^3.3.11"
|
||||
}
|
||||
}
|
||||
4
src/main.ts
Normal file
4
src/main.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { get_startup_arguments } from "./tiny/env";
|
||||
(async function main(argv: string[]) {
|
||||
console.log(argv);
|
||||
})(get_startup_arguments());
|
||||
36
src/tiny/env.ts
Normal file
36
src/tiny/env.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* JavaScript 运行环境
|
||||
*/
|
||||
export enum JavaScriptRuntime {
|
||||
/** 未知 */
|
||||
Unknown,
|
||||
/** NodeJS 运行时 */
|
||||
NodeJS,
|
||||
/** 浏览器 */
|
||||
Browser,
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的运行环境
|
||||
*/
|
||||
export function get_runtime(): JavaScriptRuntime {
|
||||
if (typeof window == 'object' && typeof document == 'object') {
|
||||
return JavaScriptRuntime.Browser;
|
||||
} else if (typeof process == 'object' && process.release.name == 'node') {
|
||||
return JavaScriptRuntime.NodeJS;
|
||||
}
|
||||
return JavaScriptRuntime.Unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取启动参数
|
||||
*/
|
||||
export function get_startup_arguments(): string[] {
|
||||
switch (get_runtime()) {
|
||||
case JavaScriptRuntime.NodeJS:
|
||||
return process.argv;
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
22
tsconfig.json
Normal file
22
tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2018",
|
||||
"module": "commonjs",
|
||||
"lib": [ "ESNext", "DOM" ],
|
||||
"declaration": false,
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"sourceMap": true,
|
||||
"outDir": "dist",
|
||||
"moduleResolution": "node",
|
||||
"baseUrl": "src",
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules/**/*"
|
||||
]
|
||||
}
|
||||
38
webpack.config.js
Normal file
38
webpack.config.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
||||
const workSpaceDir = path.resolve(__dirname);
|
||||
|
||||
module.exports = (env) => {
|
||||
if (!env) { env = {production: false};}
|
||||
console.log("Compile environment:", env);
|
||||
return ({
|
||||
target: 'node',
|
||||
entry: path.join(workSpaceDir, 'src/main.ts'),
|
||||
output: {
|
||||
path: path.join(workSpaceDir, 'dist'),
|
||||
filename: 'binary.js'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{ test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ },
|
||||
{ test:/\.ya?ml$/, use: [ "json-loader", "yaml-loader" ] },
|
||||
{ test:/\.(html|txt|md)$/, use: "raw-loader" },
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
extensions: [
|
||||
'.tsx', '.ts', '.js',
|
||||
".yaml", ".html", ".md", ".txt"
|
||||
],
|
||||
plugins: [
|
||||
new TsconfigPathsPlugin({configFile: path.join(workSpaceDir, 'tsconfig.json')})
|
||||
]
|
||||
},
|
||||
externals: {},
|
||||
plugins: [
|
||||
],
|
||||
devtool: env.production ? "" : "source-map",
|
||||
mode: "development",
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user