AntAR 开发的工作流程

让 AntAR 连接 npm 的世界

全局安装(只需要一次)

安装 typescript、ts-node、@types/node、ts-loader

1
npm install -g typescript ts-node @types/node ts-loader

安装 webpack

1
npm install -g webpack webpack-cli @types/webpack

安装 crypto-js 加密模块

1
npm install -g crypto-js @types/crypto-js

链接(每个新项目都需要)

1
2
3
4
npm link @types/node
npm link ts-loader
npm link webpack webpack-cli @types/webpack
npm link crypto-js @types/crypto-js

npm 初始化,生成 package.json

1
npm --init -y

tsc 初始化

1
tsc -init

修改 tsconfig.json 文件

1
2
3
4
5
6
7
8
9
10
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": false,
"esModuleInterop": true
},
"include": ["${YourProjectPath}"],
"exclude": ["node_modules", "${YourElsePath}"]
}

创建 webpack.config.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import webpack from 'webpack';

const projectPath = __dirname + '/${YourProjectPath}/';
const fileName = '${YourFilename}';

const config: webpack.Configuration = {
mode: 'production', //'none', 'development' or 'production'
entry: projectPath + fileName + '.ts',
output: {
path: projectPath,
filename: fileName + '.js'
},
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /${YourElsePath}/
}
]
}
};

export default config;

项目中引用加密模块示例

1
import SHA1 from 'crypto-js/sha1';

webpack 启动项目

1
webpack -w