Commit 81826afd by 杨明

init

1 parent 2c88d7df
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-28 10:33:29
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-11-28 10:33:38
* @FilePath: \rollup_demo\.eslintrc.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
module.exports = {
root: true,
env: {
node: true
},
parserOptions: {
ecmaVersion: 7,
sourceType: 'module'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
}
}
node_modules
dist
\ No newline at end of file \ No newline at end of file
{
"printWidth": 1800,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "none",
"semi": false,
"wrap_line_length": 1820,
"wrap_attributes": "auto",
"proseWrap": "always",
"arrowParens": "avoid",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "ignore",
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"jsxBracketSameLine": true,
"files.insertFinalNewline": true,
"useTabs": false,
"prettier.ignorePath": ".prettierignore",
"eslintIntegration": true,
"overrides": [
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
}
],
"endOfLine": "auto"
}
\ No newline at end of file \ No newline at end of file
<!--
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-27 11:00:54
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-11-28 10:29:36
* @FilePath: \rollup_demo\README.md
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
# 前端构建
前端技术方案:
* 前端构建方式: rollup
* js语言: typeScript 4.9.5
## 文件组织
* `src/`
* `main.ts` —— 入口文件
* `index.html` —— 模版文件
* `dist/` —— 构建结果目录
## 开发环境配置
1. 把代码库 clone 到本地。
1. 进入本项目的根目录,执行以下命令即可运行开发环境:
```sh
# 下载依赖
npm install
# 运行
npm run dev
# 打包
npm run build
```
## 构建与部署
#### 前端构建
* 运行 `npm run build`。
* 构建结果在 `dist/` 目录中。
{
"name": "glsx-tracker-javascript",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "cross-env NODE_ENV=development rollup -c -w",
"build": "cross-env NODE_ENV=produaction rollup -c"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"cross-env": "^7.0.3",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-serve": "^1.1.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.2",
"rollup": "^2.10.9",
"typescript": "^4.9.5"
}
}
<!--
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-24 17:29:53
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-11-27 11:18:25
* @FilePath: \rollup_demo\public\index.html
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script src="../dist/glsx-tracker-javascript.js"></script>
</body>
</html>
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-24 16:44:09
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-11-28 14:22:09
* @FilePath: \rollup_demo\rollup.config.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import ts from 'rollup-plugin-typescript2'
import path from 'path'
import serve from 'rollup-plugin-serve'
import livereload from 'rollup-plugin-livereload'
import { terser } from 'rollup-plugin-terser'
import resolve from 'rollup-plugin-node-resolve'
import repacle from 'rollup-plugin-replace'
import { name } from './package.json'
const isDev = () => {
return process.env.NODE_ENV === 'development'
}
export default {
input: './src/main.ts',
output: {
file: path.resolve(__dirname, `./dist/${name}.js`),
format: 'umd',
sourcemap: false
},
plugins: [
ts(),
terser({
compress: {
drop_console: !isDev()
}
}),
repacle({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
resolve(['.js', '.ts']),
isDev() && livereload(),
isDev() &&
serve({
port: 8870,
open: true,
openPage: '/public/index.html'
})
]
}
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-24 17:28:02
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-11-28 14:14:11
* @FilePath: \rollup_demo\src\main.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import Request from './modules/request'
const request = new Request('https://www.xxx.com', 'ajax')
console.log(request.url)
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-27 11:13:22
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-11-28 10:15:18
* @FilePath: \rollup_demo\src\modules\request.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { requestType } from 'request'
class Request {
public url: string
public method: requestType
constructor(url: string, method: requestType) {
this.url = url
this.method = method
}
}
export default Request
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-28 14:10:03
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-11-28 14:11:42
* @FilePath: \glsx-tracker-javascript\src\types\request.d.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
declare module 'request' {
export type requestType = 'ajax' | 'image' | 'fetch' | 'beacon'
}
File mode changed
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!