Skip to content
This repository was archived by the owner on Nov 18, 2021. It is now read-only.

Commit 6e76991

Browse files
committed
完成打包
1 parent dab3c35 commit 6e76991

File tree

9 files changed

+106
-59
lines changed

9 files changed

+106
-59
lines changed

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

.vscode/tasks.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

build/build.js

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ fs.emptyDirSync(path.resolve(__dirname, '../dist'))
66

77
// 编译 js
88
const rollup = require('rollup')
9+
const typescript = require('rollup-plugin-typescript2')
910
const uglifyJS = require('uglify-js')
1011
const pkg = require('../package.json')
1112

@@ -17,31 +18,42 @@ const banner = [
1718
' */'
1819
].join('\n')
1920

20-
rollup.rollup({
21-
entry: path.resolve(__dirname, '../chrome-call.js'),
22-
plugins: []
23-
}).then(bundle => {
24-
// 输出 umd 格式
25-
const { code } = bundle.generate({
26-
format: 'umd',
27-
moduleName: 'chromeCall',
28-
banner
21+
rollup
22+
.rollup({
23+
input: path.resolve(__dirname, '../src/index.ts'),
24+
plugins: [
25+
typescript({
26+
tsconfig: 'tsconfig.build.json'
27+
})
28+
]
2929
})
30+
.then(bundle => {
31+
// 输出 umd 格式
32+
bundle
33+
.generate({
34+
format: 'umd',
35+
name: 'chromeCall',
36+
banner
37+
})
38+
.then(({ code }) => {
39+
fs.writeFile(path.resolve(__dirname, '../dist/chrome-call.js'), code)
40+
fs.writeFile(
41+
path.resolve(__dirname, '../dist/chrome-call.min.js'),
42+
uglifyJS.minify(code, { output: { comments: /^!/ } }).code
43+
)
44+
})
3045

31-
fs.writeFile(path.resolve(__dirname, '../dist/chrome-call.js'), code)
32-
fs.writeFile(path.resolve(__dirname, '../dist/chrome-call.min.js'), uglifyJS.minify(code, { output: { comments: /^!/ } }).code)
46+
// 输出 es 格式
47+
bundle.write({
48+
file: path.resolve(__dirname, '../dist/chrome-call.esm.js'),
49+
format: 'es',
50+
banner
51+
})
3352

34-
// 输出 es 格式
35-
bundle.write({
36-
dest: path.resolve(__dirname, '../dist/chrome-call.esm.js'),
37-
format: 'es',
38-
banner
53+
// 输出 cjs 格式
54+
bundle.write({
55+
file: path.resolve(__dirname, '../dist/chrome-call.common.js'),
56+
format: 'cjs',
57+
banner
58+
})
3959
})
40-
41-
// 输出 cjs 格式
42-
bundle.write({
43-
dest: path.resolve(__dirname, '../dist/chrome-call.common.js'),
44-
format: 'cjs',
45-
banner
46-
})
47-
})

package-lock.json

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "chrome-call",
33
"version": "3.0.0",
4-
"description": "A really simple way to call the original chrome javascript API and return a Promise.",
4+
"description":
5+
"A really simple way to call the original chrome javascript API and return a Promise.",
56
"main": "dist/chrome-call.common.js",
67
"module": "dist/chrome-call.esm.js",
8+
"types": "dist/index.d.ts",
79
"unpkg": "dist/chrome-call.js",
810
"repository": {
911
"type": "git",
@@ -18,9 +20,7 @@
1820
"lint": "tslint -p tsconfig.json -t verbose",
1921
"prepublishOnly": "npm run build"
2022
},
21-
"files": [
22-
"dist"
23-
],
23+
"files": ["dist"],
2424
"devDependencies": {
2525
"@types/chrome": "0.0.56",
2626
"@types/karma-jasmine": "0.0.29",
@@ -35,19 +35,14 @@
3535
"karma-typescript": "^3.0.9",
3636
"phantomjs-prebuilt": "^2.1.13",
3737
"rollup": "^0.52.3",
38+
"rollup-plugin-typescript2": "^0.9.0",
3839
"tslint": "^5.8.0",
3940
"tslint-config-prettier": "^1.6.0",
4041
"tslint-config-standard": "^7.0.0",
4142
"typescript": "^2.6.2",
4243
"uglify-js": "^3.0.23"
4344
},
44-
"keywords": [
45-
"chrome",
46-
"ext",
47-
"extension",
48-
"app",
49-
"promise"
50-
],
45+
"keywords": ["chrome", "ext", "extension", "app", "promise"],
5146
"author": "Milk Lee <me@limingkai.cn> (http://www.limingkai.cn/)",
5247
"license": "MIT",
5348
"homepage": "https://github.com/lmk123/chrome-call"

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface AnyFn<T> {
1+
interface AnyFn<T> {
22
(this: T, ...args: any[]): any
33
}
44

test/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import chromeCall, { AnyFn } from '../src/index'
1+
import chromeCall from '../src/index'
22

33
// @ts-ignore
44
window.chrome = {
55
runtime: {}
66
}
77

88
interface FakeObj {
9-
method: (this: FakeObj, key: string, cb: AnyFn<void>) => void
9+
method: (this: FakeObj, key: string, cb: (...args: any[]) => any) => void
1010
}
1111

1212
const fakeObj: FakeObj = {

tsconfig.build.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src/**/*.ts"]
4+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"declaration": true
1313
},
1414
"include": [
15-
"src/**/*.ts",
15+
"src/**/*.ts" ,
1616
"test/**/*.ts"
1717
]
1818
}

0 commit comments

Comments
 (0)