Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhaijing committed Oct 9, 2018
0 parents commit 8485231
Show file tree
Hide file tree
Showing 27 changed files with 5,886 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"presets": [
["env",
{
"targets": {
"browsers": "last 2 versions, > 1%, ie >= 6, Android >= 4, iOS >= 6, and_uc > 9",
"node": "0.10"
},
"modules": false,
"loose": false
}]
],
"plugins": [
["transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": false,
"moduleName": "babel-runtime"
}]
]
}
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[{*.js,*.css,*.html}]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
insert_final_newline = true

[{package.json,.*rc,*.yml}]
indent_style = space
indent_size = 2
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### 问题是什么
问题的具体描述,尽量详细

### 环境
- 手机: 小米6
- 系统:安卓7.1.1
- 浏览器:chrome 61
- 使用的版本:0.2.0
- 其他版本信息

### 在线例子
如果有请提供在线例子

### 其他
其他信息
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
config
demo
src
test
.babelrc
.editorconfig
.travis.yml
CHANGELOG.md
package-lock.json
TODO.md
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "8"
- "6"
- "4"
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 变更日志

## 0.2.0 / 2018-3-10

- 支持banner
- 添加es5-shim

## 0.1.0 / 2018-3-1

- ES6编写源码,编译生成生产代码
- 第三方依赖自动注入
- 支持浏览器原生
- 支持AMD,CMD
- 支持Webpack,Rollup,fis等
- 支持Node
- 集成单元测试环境
- 集成eslint
- 集成[travis-ci](https://www.travis-ci.org/)
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (C) 2017-2018 yanhaijing

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
149 changes: 149 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# [base](https://github.com/jsmini/base)

[![](https://img.shields.io/badge/Powered%20by-jslib%20base-brightgreen.svg)](https://github.com/yanhaijing/jslib-base)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jsmini/base/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/jsmini/base.svg?branch=master)](https://travis-ci.org/jsmini/base)
[![npm](https://img.shields.io/badge/npm-0.2.0-orange.svg)](https://www.npmjs.com/package/base)
[![NPM downloads](http://img.shields.io/npm/dm/@jsmini/base.svg?style=flat-square)](http://www.npmtrends.com/@jsmini/base)
[![Percentage of issues still open](http://isitmaintained.com/badge/open/jsmini/base.svg)](http://isitmaintained.com/project/jsmini/base "Percentage of issues still open")

最好用的js第三方库脚手架,fork或clone本仓库,即可搭建完成一个新库的基础框架

## 特性

- ES6编写源码,编译生成生产代码
- 集成 babel-runtime (默认关闭)
- 第三方依赖自动注入(自动剔除第三方依赖无用代码tree shaking)
- 多环境支持(支持浏览器原生,支持AMD,CMD,支持Webpack,Rollup,fis等,支持Node)
- 集成单元测试环境
- 集成代码风格校验eslint
- 集成可持续构建工具[travis-ci](https://www.travis-ci.org/)
- 支持自定义banner
- 集成[jsmini](https://github.com/jsmini)
- 集成ISSUE_TEMPLATE
- 支持[sideEffects](https://juejin.im/post/5b4ff9ece51d45190c18bb65)
- 支持一键重命名

**注意:** 如果不同时使用 export 与 export default 可打开legacy模式,legacy模式下的模块系统可以兼容ie6-8,见rollup配置文件

## 兼容性
单元测试保证支持如下环境:

| IE | CH | FF | SF | OP | IOS | 安卓 | Node |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ----- |
| 6+ | 23+ | 4+ | 6+ | 10+ | 5+ | 2.3+ | 0.10+ |

**注意:编译代码依赖ES5环境,对于ie6-8需要引入[es5-shim](http://github.com/es-shims/es5-shim/)才可以兼容,可以查看[demo/demo-global.html](../demo/demo-global.html)中的例子**

## 目录介绍

```
.
├── demo 使用demo
├── dist 编译产出代码
├── doc 项目文档
├── src 源代码目录
├── test 单元测试
├── CHANGELOG.md 变更日志
└── TODO.md 计划功能
```

## 如何使用
通过npm下载安装代码

```bash
$ npm install --save @jsmini/base
```

如果你是node环境

```js
var name = require('@jsmini/base').name;
```

如果你是webpack等环境

```js
import { name } from '@jsmini/base';
```

如果你是requirejs环境

```js
requirejs(['node_modules/@jsmini/base/dist/index.aio.js'], function (jsmini_base) {
var name = jsmini_base.name;
})
```

如果你是浏览器环境

```html
<script src="node_modules/@jsmini/base/dist/index.aio.js"></script>

<script>
var name = jsmini_base.name;
</script>
```

## 文档
[API](https://github.com/jsmini/base/blob/master/doc/api.md)

## 贡献指南
首次运行需要先安装依赖

```bash
$ npm install
```

一键打包生成生产代码

```bash
$ npm run build
```

运行单元测试,浏览器环境需要手动测试,位于`test/browser`

```bash
$ npm test
```

修改package.json中的版本号,修改README.md中的版本号,修改CHANGELOG.md,然后发布新版

```bash
$ npm run release
```

将新版本发布到npm

```bash
$ npm publish --access=public
```

重命名项目名称,首次初始化项目是需要修改名字,或者后面项目要改名时使用,需要修改`rename.js`中的`fromName``toName`,会自动重命名下面文件中的名字

- README.md 中的信息
- package.json 中的信息
- config/rollup.js 中的信息
- test/browser/index.html 中的仓库名称

```bash
$ npm run rename # 重命名命令
```

## 贡献者列表
[contributors](https://github.com/jsmini/base/graphs/contributors)

## 更新日志
[CHANGELOG.md](https://github.com/jsmini/base/blob/master/CHANGELOG.md)

## 计划列表
[TODO.md](https://github.com/jsmini/base/blob/master/TODO.md)

## 谁在使用

- [type](https://github.com/jsmini/type)
- [is](https://github.com/jsmini/is)
- [guid](https://github.com/jsmini/guid)
- [inherits](https://github.com/jsmini/inherits)
- [event](https://github.com/jsmini/event)
- [console](https://github.com/jsmini/console)
5 changes: 5 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 计划列表
这里列出会在未来添加的新功能,和已经完成的功能

- [X] 已完成
- [ ] 未完成
30 changes: 30 additions & 0 deletions config/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-console": 0
}
};
31 changes: 31 additions & 0 deletions config/rollup.config.aio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// rollup.config.js

var babel = require("rollup-plugin-babel");
var nodeResolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');

var common = require('./rollup.js');

export default {
input: 'src/index.js',
output: {
file: 'dist/index.aio.js',
format: 'umd',
// 如果不同时使用 export 与 export default 可打开legacy
// legacy: true,
name: common.name,
banner: common.banner,
},
plugins: [
nodeResolve({
main: true
}),
commonjs({
include: 'node_modules/**',
}),
babel({
runtimeHelpers: true,
exclude: 'node_modules/**'
})
]
};
7 changes: 7 additions & 0 deletions config/rollup.config.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import config from './rollup.config';

// ES output
config.output.format = 'es';
config.output.file = 'dist/index.esm.js';

export default config;
21 changes: 21 additions & 0 deletions config/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// rollup.config.js

var babel = require('rollup-plugin-babel');
var common = require('./rollup.js');

export default {
input: 'src/index.js',
output: {
file: 'dist/index.js',
format: 'cjs',
// 如果不同时使用 export 与 export default 可打开legacy
// legacy: true,
banner: common.banner,
},
plugins: [
babel({
runtimeHelpers: true,
exclude: 'node_modules/**'
})
]
};
17 changes: 17 additions & 0 deletions config/rollup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var pkg = require('../package.json');

// 兼容 base 和 @jsmini/base,@jsmini/base 替换为 jsmini_base
var name = pkg.name.replace('@', '').replace(/\//g, '_');
var version = pkg.version;

var banner =
`/*!
* base ${version} (https://github.com/jsmini/base)
* API https://github.com/jsmini/base/blob/master/doc/api.md
* Copyright 2017-${(new Date).getFullYear()} jsmini. All Rights Reserved
* Licensed under MIT (https://github.com/jsmini/base/blob/master/LICENSE)
*/
`;

exports.name = name;
exports.banner = banner;
18 changes: 18 additions & 0 deletions demo/demo-amd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="../node_modules/es5-shim/es5-shim.js"></script>
<script src="../node_modules/es5-shim/es5-sham.js"></script>

<script src='./js/require.js'></script>
<script>
requirejs(['../dist/index.aio.js'], function (base) {
console.log(base.name)
})
</script>
</body>
</html>
Loading

0 comments on commit 8485231

Please sign in to comment.