Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 26, 2021. It is now read-only.

Commit 05c55fc

Browse files
committed
chore: 新增rollup构建
1 parent 82f9b81 commit 05c55fc

File tree

10 files changed

+1196
-1789
lines changed

10 files changed

+1196
-1789
lines changed

‎.babelrc‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
{
2-
"presets": ["@babel/env"],
3-
"plugins": ["@babel/plugin-proposal-class-properties"]
2+
"presets": [
3+
[
4+
"env",
5+
{
6+
"modules": false
7+
}
8+
]
9+
],
10+
"plugins": [
11+
"transform-object-rest-spread",
12+
"transform-object-assign"
13+
],
14+
"env": {
15+
"test": {
16+
"plugins": [ "istanbul" ]
17+
}
18+
}
419
}

‎.eslintignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/*.js

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
.DS_Store
22
node_modules/
3-
dist/
43
npm-debug.log*
54
yarn-debug.log*
65
yarn-error.log*
76
test/unit/coverage
7+
test/e2e/reports
8+
selenium-debug.log
89

910
# Editor directories and files
1011
.idea

‎build/build.js‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const zlib = require('zlib')
4+
const uglify = require('uglify-js')
5+
const rollup = require('rollup')
6+
const configs = require('./configs')
7+
8+
if (!fs.existsSync('dist')) {
9+
fs.mkdirSync('dist')
10+
}
11+
12+
build(Object.keys(configs).map(key => configs[key]))
13+
14+
function build (builds) {
15+
let built = 0
16+
const total = builds.length
17+
const next = () => {
18+
buildEntry(builds[built]).then(() => {
19+
built++
20+
if (built < total) {
21+
next()
22+
}
23+
}).catch(logError)
24+
}
25+
26+
next()
27+
}
28+
29+
function buildEntry ({ input, output }) {
30+
const isProd = /min\.js$/.test(output.file)
31+
return rollup.rollup(input)
32+
.then(bundle => bundle.generate(output))
33+
.then(({ code }) => {
34+
if (isProd) {
35+
var minified = (output.banner ? output.banner + '\n' : '') + uglify.minify(code, {
36+
output: {
37+
/* eslint-disable camelcase */
38+
ascii_only: true
39+
/* eslint-enable camelcase */
40+
}
41+
}).code
42+
return write(output.file, minified, true)
43+
} else {
44+
return write(output.file, code)
45+
}
46+
})
47+
}
48+
49+
function write (dest, code, zip) {
50+
return new Promise((resolve, reject) => {
51+
function report (extra) {
52+
console.log(blue(path.relative(process.cwd(), dest)) + ' ' + getSize(code) + (extra || ''))
53+
resolve()
54+
}
55+
56+
fs.writeFile(dest, code, err => {
57+
if (err) return reject(err)
58+
if (zip) {
59+
zlib.gzip(code, (err, zipped) => {
60+
if (err) return reject(err)
61+
report(' (gzipped: ' + getSize(zipped) + ')')
62+
})
63+
} else {
64+
report()
65+
}
66+
})
67+
})
68+
}
69+
70+
function getSize (code) {
71+
return (code.length / 1024).toFixed(2) + 'kb'
72+
}
73+
74+
function logError (e) {
75+
console.log(e)
76+
}
77+
78+
function blue (str) {
79+
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
80+
}

‎build/configs.js‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const path = require('path')
2+
const replace = require('rollup-plugin-replace')
3+
const babel = require('rollup-plugin-babel')
4+
const version = process.env.VERSION || require('../package.json').version
5+
const banner =
6+
`/**
7+
* vue-webview-js-bridge v${version}
8+
* (c) ${new Date().getFullYear()} Kntt
9+
* @license MIT
10+
*/`
11+
12+
const resolve = _path => path.resolve(__dirname, '../', _path)
13+
14+
const configs = {
15+
umdDev: {
16+
input: resolve('lib/index.js'),
17+
file: resolve('dist/vue-webview-js-bridge.js'),
18+
format: 'umd',
19+
env: 'development'
20+
},
21+
umdProd: {
22+
input: resolve('lib/index.js'),
23+
file: resolve('dist/vue-webview-js-bridge.min.js'),
24+
format: 'umd',
25+
env: 'production'
26+
},
27+
esm: {
28+
input: resolve('lib/index.js'),
29+
file: resolve('dist/vue-webview-js-bridge.esm.js'),
30+
format: 'es'
31+
}
32+
}
33+
34+
function genConfig (opts) {
35+
const config = {
36+
input: {
37+
input: opts.input,
38+
plugins: [
39+
replace({
40+
__VERSION__: version
41+
}),
42+
babel({
43+
exclude: 'node_modules/**',
44+
plugins: ['external-helpers']
45+
})
46+
]
47+
},
48+
output: {
49+
banner,
50+
file: opts.file,
51+
format: opts.format,
52+
name: 'VueWebviewJsBridge'
53+
}
54+
}
55+
56+
if (opts.env) {
57+
config.input.plugins.unshift(replace({
58+
'process.env.NODE_ENV': JSON.stringify(opts.env)
59+
}))
60+
}
61+
62+
return config
63+
}
64+
65+
function mapValues (obj, fn) {
66+
const res = {}
67+
Object.keys(obj).forEach(key => {
68+
res[key] = fn(obj[key], key)
69+
})
70+
return res
71+
}
72+
73+
module.exports = mapValues(configs, genConfig)

‎example/client/main.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import '@babel/polyfill'
1+
import 'babel-polyfill'
22
import Vue from 'vue'
33
import App from './App.vue'
44
import VueJsBridge from 'vue-webview-js-bridge'

‎example/client/webpack.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525

2626
resolve: {
2727
alias: {
28-
'vue-webview-js-bridge': path.resolve(__dirname, '../../lib/index.js')
28+
'vue-webview-js-bridge': path.resolve(__dirname, '../..')
2929
}
3030
},
3131

‎package.json‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,47 @@
33
"version": "0.0.5",
44
"author": "Kntt<kntt9968@gmail.com>",
55
"description": "webview-js-bridge plugin for Vue.js",
6-
"keywords": ["vue", "webview", "plugin", "JsBridge", "WebViewJavascriptBridge", "vue-js-bridge", "webview-js-bridge", "vue-webview-js-bridge"],
7-
"main": "lib/index.js",
6+
"keywords": [
7+
"vue",
8+
"webview",
9+
"plugin",
10+
"JsBridge",
11+
"WebViewJavascriptBridge",
12+
"vue-js-bridge",
13+
"webview-js-bridge",
14+
"vue-webview-js-bridge"
15+
],
16+
"main": "dist/vue-webview-js-bridge.js",
817
"types": "types/index.d.ts",
918
"files": [
19+
"dist",
1020
"lib",
1121
"types"
1222
],
1323
"scripts": {
1424
"dev": "node example/client/server.js",
25+
"build": "node build/build.js",
1526
"release": "bash release.sh",
16-
"changelog": "conventional-changelog -p angular -i CHANGELOG.MD -s",
1727
"lint": "eslint --ext .js lib --fix"
1828
},
1929
"devDependencies": {
20-
"@babel/core": "^7.3.3",
21-
"@babel/plugin-proposal-class-properties": "^7.3.3",
22-
"@babel/polyfill": "^7.2.5",
23-
"@babel/preset-env": "^7.3.1",
24-
"babel-loader": "^8.0.5",
25-
"conventional-changelog-cli": "^2.0.12",
30+
"babel-core": "^6.22.1",
31+
"babel-loader": "^7.1.2",
32+
"babel-plugin-external-helpers": "^6.22.0",
33+
"babel-plugin-istanbul": "^5.0.1",
34+
"babel-plugin-transform-object-assign": "^6.22.0",
35+
"babel-plugin-transform-object-rest-spread": "^6.23.0",
36+
"babel-polyfill": "^6.22.0",
37+
"babel-preset-env": "^1.5.1",
2638
"css-loader": "^2.1.0",
27-
"eslint": "^5.14.0",
39+
"eslint": "^4.7.0",
2840
"eslint-plugin-vue-libs": "^3.0.0",
2941
"express": "^4.16.4",
3042
"ghooks": "^2.0.4",
43+
"rollup": "^0.65.0",
44+
"rollup-plugin-babel": "^3.0.7",
45+
"rollup-plugin-replace": "^2.0.0",
46+
"uglify-js": "^3.4.9",
3147
"validate-commit-msg": "^2.14.0",
3248
"vue": "^2.6.6",
3349
"vue-loader": "^15.6.2",

‎release.sh‎

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /