Skip to content

Commit 82d9aac

Browse files
author
caoruining
committed
''
0 parents  commit 82d9aac

13 files changed

+5250
-0
lines changed

.gitignore

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/dist/*
2+
# Logs
3+
logs
4+
*.log
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
lerna-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# TypeScript v1 declaration files
46+
typings/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Microbundle cache
58+
.rpt2_cache/
59+
.rts2_cache_cjs/
60+
.rts2_cache_es/
61+
.rts2_cache_umd/
62+
63+
# Optional REPL history
64+
.node_repl_history
65+
66+
# Output of 'npm pack'
67+
*.tgz
68+
69+
# Yarn Integrity file
70+
.yarn-integrity
71+
72+
# dotenv environment variables file
73+
.env
74+
.env.test
75+
76+
# parcel-bundler cache (https://parceljs.org/)
77+
.cache
78+
79+
# Next.js build output
80+
.next
81+
82+
# Nuxt.js build / generate output
83+
.nuxt
84+
dist
85+
86+
# Gatsby files
87+
.cache/
88+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
89+
# https://nextjs.org/blog/next-9-1#public-directory-support
90+
# public
91+
92+
# vuepress build output
93+
.vuepress/dist
94+
95+
# Serverless directories
96+
.serverless/
97+
98+
# FuseBox cache
99+
.fusebox/
100+
101+
# DynamoDB Local files
102+
.dynamodb/
103+
104+
# TernJS port file
105+
.tern-port
106+
107+
#idea
108+
.idea/

example.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom';
3+
import CheckTime from './lib/checkTime';
4+
5+
6+
7+
8+
ReactDOM.render(
9+
<CheckTime/>,document.getElementById("root")
10+
);

index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-cmn-Hans">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title><%= htmlWebpackPlugin.options.title %></title>
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
</body>
11+
</html>

lib/checkTime.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React, { Fragment } from 'react'
2+
import { Button, message } from "antd";
3+
import moment from "moment";
4+
5+
6+
function CheckTime() {
7+
const showTime = () => {
8+
message.info(`当前时间为${moment().format('YYYY-MM-DD hh-mm-ss')}`)
9+
};
10+
11+
return (
12+
<Fragment>
13+
<Button onClick={() => showTime}>查看当前时间</Button>
14+
</Fragment>
15+
)
16+
}
17+
18+
export default CheckTime

lib/index.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom';
3+
import CheckTime from './checkTime';
4+
5+
6+
ReactDOM.render(
7+
<CheckTime/>,
8+
document.getElementById("root")
9+
);
10+
export { CheckTime }

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "npmDemo",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "webpack.config.js",
6+
"directories": {
7+
"lib": "lib"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1",
11+
"start": "webpack-dev-server --config webpack.dev.js",
12+
"build": "webpack --config webpack.prod.js"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/RainingC/npmDemo.git"
17+
},
18+
"keywords": [],
19+
"author": "",
20+
"license": "ISC",
21+
"bugs": {
22+
"url": "https://github.com/RainingC/npmDemo/issues"
23+
},
24+
"homepage": "https://github.com/RainingC/npmDemo#readme",
25+
"devDependencies": {
26+
"@types/react": "^16.9.39",
27+
"@types/react-dom": "^16.9.8",
28+
"awesome-typescript-loader": "^5.2.1",
29+
"html-webpack-plugin": "^4.3.0",
30+
"typescript": "^3.9.5",
31+
"webpack": "^4.43.0",
32+
"webpack-cli": "^3.3.12",
33+
"webpack-dev-server": "^3.11.0"
34+
},
35+
"dependencies": {
36+
"antd": "^4.3.5",
37+
"moment": "^2.27.0",
38+
"react": "^16.13.1",
39+
"react-dom": "^16.13.1"
40+
}
41+
}

publish.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 初始化一个package.json文件
2+
npm init -y
3+
4+
# 安装webpack webpack-cli
5+
yarn add webpack webpack-cli --dev
6+
7+
# 安装ts
8+
yarn add typescript --dev
9+
10+
# 安装webpack插件
11+
# 让webpack可以编译ts文件
12+
yarn add awesome-typescript-loader --dev
13+
14+
# 安装server来提供web服务
15+
yarn add webpack-dev-server --dev
16+
# 自动在html中引入打包好的js文件
17+
yarn add html-webpack-plugin --dev
18+
19+
#安装react 除了安装源代码包,还得安装类型文件
20+
yarn add react
21+
yarn add react-dom
22+
yarn add @types/react --dev
23+
yarn add @types/react-dom --dev

tsconfig.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "dist",
4+
"declaration": true,
5+
"baseUrl": ".",
6+
"module": "esnext",
7+
"target": "es5",
8+
"lib": ["es6", "dom"],
9+
"sourceMap": true,
10+
"jsx": "react",
11+
"moduleResolution": "node",
12+
"rootDir": ".",
13+
"forceConsistentCasingInFileNames": true,
14+
"noImplicitReturns": true,
15+
"noImplicitThis": true,
16+
"noImplicitAny": true,
17+
"importHelpers": true,
18+
"strictNullChecks": true,
19+
// "suppressImplicitAnyIndexErrors": true,
20+
// https://github.com/Microsoft/TypeScript/issues/28762#issuecomment-443406607
21+
// "allowSyntheticDefaultImports": true,
22+
"esModuleInterop": true,
23+
"noUnusedLocals": true
24+
},
25+
"include": [
26+
"lib/**/*"
27+
],
28+
"exclude": [
29+
"node_modules",
30+
"build",
31+
"dist",
32+
"scripts",
33+
"acceptance-tests",
34+
"webpack",
35+
"jest",
36+
"src/setupTests.ts",
37+
"*.js"
38+
]
39+
}

tslint.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"extends": ["tslint:recommended", "tslint-react"],
3+
"rules": {
4+
"no-console": [false, "log", "error"],
5+
"jsx-no-multiline-js": false,
6+
"whitespace": false,
7+
"no-empty-interface": false,
8+
"space-before-function-paren": false,
9+
"no-namespace": false,
10+
"label-position": false,
11+
"quotemark": [true, "single", "jsx-double"],
12+
"member-access": false,
13+
"semicolon": [true, "always", "ignore-bound-class-methods"],
14+
"no-unused-expression": [true, "allow-fast-null-checks"],
15+
"member-ordering": false,
16+
"trailing-comma": false,
17+
"arrow-parens": false,
18+
"jsx-self-close": false,
19+
"max-line-length": false,
20+
"interface-name": false,
21+
"no-empty": false,
22+
"comment-format": false,
23+
"ordered-imports": false,
24+
"object-literal-sort-keys": false,
25+
"eofline": false,
26+
"jsx-no-lambda": false,
27+
"no-trailing-whitespace": false,
28+
"jsx-alignment": false,
29+
"jsx-wrap-multilines": false,
30+
"no-shadowed-variable": [
31+
false,
32+
{
33+
"class": true,
34+
"enum": true,
35+
"function": false,
36+
"interface": false,
37+
"namespace": true,
38+
"typeAlias": false,
39+
"typeParameter": false
40+
}
41+
]
42+
},
43+
"linterOptions": {
44+
"exclude": [
45+
"config/**/*.js",
46+
"node_modules/**/*.ts",
47+
"coverage/lcov-report/*.js"
48+
]
49+
}
50+
}

webpack.config.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const path = require('path');
2+
const HtmlWebpackPlugin = require('html-webpack-plugin');
3+
4+
module.exports = {
5+
mode: "development",
6+
entry:{
7+
index: './example.tsx',
8+
},
9+
output: {
10+
filename: "index.js",
11+
path: path.resolve(__dirname, 'dist/lib'),
12+
library: 'dsagrgaeeay',
13+
libraryTarget: 'umd',
14+
},
15+
resolve: {
16+
extensions: ['.ts', '.tsx', '.js', '.jsx'],
17+
},
18+
module:{
19+
rules:[
20+
{
21+
test: /\.tsx?$/,
22+
loader:'awesome-typescript-loader'
23+
}
24+
]
25+
},
26+
plugins: [
27+
new HtmlWebpackPlugin({
28+
template: 'index.html',
29+
})
30+
]
31+
}

webpack.dev.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const path = require('path');
2+
const HtmlWebpackPlugin = require('html-webpack-plugin');
3+
4+
module.exports = {
5+
mode: "development",
6+
entry:{
7+
index: './example.tsx',
8+
},
9+
output: {
10+
filename: "index.js",
11+
path: path.resolve(__dirname, 'dist/lib'),
12+
library: 'dsagrgaeeay',
13+
libraryTarget: 'umd',
14+
},
15+
resolve: {
16+
extensions: ['.ts', '.tsx', '.js', '.jsx'],
17+
},
18+
module:{
19+
rules:[
20+
{
21+
test: /\.tsx?$/,
22+
loader:'awesome-typescript-loader'
23+
}
24+
]
25+
},
26+
plugins: [
27+
new HtmlWebpackPlugin({
28+
template: 'index.html',
29+
})
30+
]
31+
}

0 commit comments

Comments
 (0)