Skip to content

Commit 67f4e15

Browse files
committedAug 23, 2021
Initial commit
0 parents  commit 67f4e15

25 files changed

+4074
-0
lines changed
 

‎.editorconfig

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# http://editorconfig.org
2+
# FYI:https://cloud.tencent.com/developer/article/1354509
3+
# EditorConfig文件使用INI格式。斜杠(/)作为路径分隔符,#或者;作为注释。路径支持通配符:
4+
# 表明是最顶层的配置文件,发现设为true时,才会停止查找.editorconfig文件
5+
root = true
6+
7+
# [*.{js,jsx,ts,tsx,vue}]
8+
# * 匹配除/之外的任意字符
9+
# ** 匹配任意字符串
10+
# ? 匹配任意单个字符
11+
# [name] 匹配name字符
12+
# [!name] 不匹配name字符
13+
# [s1,s2,s3] 匹配给定的字符串
14+
# [num1..num2] 匹配num1到mun2直接的整数
15+
[*]
16+
charset = utf-8 # 文件的charset。有以下几种类型:latin1, utf-8, utf-8-bom, utf-16be, utf-16le
17+
indent_style = space # 缩进使用 tab 或者 space
18+
indent_size = 2 # 缩进为 space 时,缩进的字符数
19+
tab_width = 2 # 缩进为 tab 时,缩进的宽度
20+
end_of_line = lf # 换行符的类型。lf, cr, crlf三种
21+
trim_trailing_whitespace = true # 是否将行尾空格自动删除
22+
insert_final_newline = true # 是否使文件以一个空白行结尾
23+
24+
[*.md]
25+
insert_final_newline = false
26+
trim_trailing_whitespace = false

‎.eslintignore

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
.DS_Store
2+
.svn
3+
.git
4+
node_modules/
5+
6+
# local env files
7+
.env.local
8+
.env.*.local
9+
10+
# Log files
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
pnpm-debug.log*
15+
16+
# Editor directories and files
17+
.idea
18+
.vscode
19+
*.suo
20+
*.ntvs*
21+
*.njsproj
22+
*.sln
23+
*.sw?
24+
25+
# VS Code
26+
.vscode/
27+
28+
# Next.js build output
29+
.next
30+
out
31+
32+
# Optional npm cache directory
33+
.npm
34+
35+
# Nuxt.js build / generate output
36+
.nuxt
37+
38+
# vuepress build output
39+
.vuepress/dist
40+
41+
# yarn v2
42+
.yarn/cache
43+
.yarn/unplugged
44+
.yarn/build-state.yml
45+
.yarn/install-state.gz
46+
.pnp.*
47+
48+
doc/
49+
tests/
50+
dist/
51+
wwwroot/
52+
build/
53+
*.md
54+
.husky

‎.eslintrc.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// ? How would you like to use ESLint? To check syntax, find problems, and enforce code style
2+
// ? What type of modules does your project use? JavaScript modules (import/export)
3+
// ? Which framework does your project use? None of these
4+
// ? Does your project use TypeScript? No
5+
// ? Where does your code run? Browser, Node
6+
// ? How would you like to define a style for your project? Answer questions about your style
7+
// ? What format do you want your config file to be in? JavaScript
8+
// ? What style of indentation do you use? Spaces
9+
// ? What quotes do you use for strings? Single
10+
// ? What line endings do you use? Unix
11+
// ? Do you require semicolons? No
12+
13+
module.exports = {
14+
'env': {
15+
'browser': true,
16+
'es6': true,
17+
'node': true
18+
},
19+
'extends': 'eslint:recommended',
20+
'globals': {
21+
'Atomics': 'readonly',
22+
'SharedArrayBuffer': 'readonly'
23+
},
24+
'parserOptions': {
25+
'ecmaVersion': 2018,
26+
'sourceType': 'module'
27+
},
28+
'rules': {
29+
'indent': [
30+
'error',
31+
2
32+
],
33+
'linebreak-style': [
34+
'error',
35+
'unix'
36+
],
37+
'quotes': [
38+
'error',
39+
'single'
40+
],
41+
'semi': [
42+
'error',
43+
'never'
44+
]
45+
}
46+
}

‎.gitignore

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.DS_Store
2+
.svn
3+
.git
4+
node_modules/
5+
6+
# local env files
7+
.env.local
8+
.env.*.local
9+
10+
# Log files
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
pnpm-debug.log*
15+
16+
# Editor directories and files
17+
.idea
18+
.vscode
19+
*.suo
20+
*.ntvs*
21+
*.njsproj
22+
*.sln
23+
*.sw?
24+
25+
# VS Code
26+
.vscode/
27+
28+
# Next.js build output
29+
.next
30+
out
31+
32+
# Optional npm cache directory
33+
.npm
34+
35+
# Nuxt.js build / generate output
36+
.nuxt
37+
38+
# vuepress build output
39+
.vuepress/dist
40+
41+
# yarn v2
42+
.yarn/cache
43+
.yarn/unplugged
44+
.yarn/build-state.yml
45+
.yarn/install-state.gz
46+
.pnp.*

‎.prettierrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"eslintIntegration": true,
3+
"stylelintIntegration": true,
4+
"tabWidth": 2,
5+
"printWidth": 100,
6+
"singleQuote": true,
7+
"semi": false,
8+
"bracketSpacing": true,
9+
"arrowParens": "avoid",
10+
"trailingComma": "es5",
11+
"useTabs": false
12+
}

‎LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 MShineRay
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# template-jslib-rollup
2+
template-jslib-rollup
3+
4+
## Q&A
5+
- Q1: 如何打包同时生成压缩和未压缩的代码?
6+
~~~
7+
output: [
8+
{ file: "lib.js", format: "cjs" },
9+
{ file: "lib.min.js", format: "cjs", plugins: [uglify() },
10+
{ file: "lib.esm.js", format: "esm" },
11+
]
12+
~~~
13+
- Q2: 如何打包不删除特定注释?
14+
~~~
15+
A1、参考rollup.config.js
16+
添加公共banner:
17+
const banner = `/*!
18+
* ${name} v${version}
19+
* (c) ${new Date().getFullYear()} ${author}
20+
* @license MIT
21+
*/
22+
23+
output: [
24+
{
25+
banner,
26+
file: `dist/${name}.amd.js`,
27+
format: 'amd', // 浏览器
28+
name
29+
},
30+
]
31+
A2、
32+
保留特定注视,例如
33+
/*!
34+
* @author xxx
35+
*/
36+
output:[
37+
{
38+
file: `dist/${name}.iife.min.js`,
39+
format: 'iife', // 浏览器
40+
name,
41+
plugins: [uglify({
42+
output:{
43+
comments: function (node, comment){
44+
//以!开头部分的注视进行保留
45+
return /^!/.test(comment.value)
46+
}
47+
}
48+
})]
49+
},
50+
]
51+
52+
A3: 指定文件拼接注释
53+
output:[
54+
{
55+
file: `dist/${name}.umd.min.js`,
56+
format: 'umd', // UMD format requires a bundle name 浏览器和 Node.js
57+
name,
58+
plugins: [uglify({
59+
output:{
60+
preamble: '/** \r\r 版本所有 \r\n 填写日期 \r\n 填写作者信息 */'
61+
}
62+
})]
63+
}
64+
]
65+
~~~
66+
67+
68+
## reference
69+
- [rollup awesome](https://github.com/rollup/awesome)

‎dist/template.jslib.rollup.amd.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*!
2+
* template.jslib.rollup v0.0.1
3+
* (c) 2021 mshineray
4+
* @license MIT
5+
*/
6+
define(function () { 'use strict';
7+
8+
var name = "template.jslib.rollup";
9+
var version = "0.0.1";
10+
11+
/*!
12+
* @createDate 2021-08-23
13+
*/
14+
var jsUtils = {};
15+
jsUtils.version = version;
16+
jsUtils.name = name;
17+
18+
return jsUtils;
19+
20+
});

‎dist/template.jslib.rollup.amd.min.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
define(function(){"use strict";var e={version:"0.0.1",name:"template.jslib.rollup"};return e});

‎dist/template.jslib.rollup.cjs.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
var name = "template.jslib.rollup";
4+
var version = "0.0.1";
5+
6+
/*!
7+
* @createDate 2021-08-23
8+
*/
9+
var jsUtils = {};
10+
jsUtils.version = version;
11+
jsUtils.name = name;
12+
13+
module.exports = jsUtils;

‎dist/template.jslib.rollup.cjs.min.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";var name="template.jslib.rollup",version="0.0.1",jsUtils={};jsUtils.version=version,jsUtils.name=name,module.exports=jsUtils;

‎dist/template.jslib.rollup.esm.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var name = "template.jslib.rollup";
2+
var version = "0.0.1";
3+
4+
/*!
5+
* @createDate 2021-08-23
6+
*/
7+
var jsUtils = {};
8+
jsUtils.version = version;
9+
jsUtils.name = name;
10+
11+
export { jsUtils as default };

‎dist/template.jslib.rollup.esm.min.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var name="template.jslib.rollup",version="0.0.1",jsUtils={};jsUtils.version=version,jsUtils.name=name;export{jsUtils as default};

‎dist/template.jslib.rollup.iife.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
this.template = this.template || {};
2+
this.template.jslib = this.template.jslib || {};
3+
this.template.jslib.rollup = (function () {
4+
'use strict';
5+
6+
var name = "template.jslib.rollup";
7+
var version = "0.0.1";
8+
9+
/*!
10+
* @createDate 2021-08-23
11+
*/
12+
var jsUtils = {};
13+
jsUtils.version = version;
14+
jsUtils.name = name;
15+
16+
return jsUtils;
17+
18+
}());
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this.template=this.template||{},this.template.jslib=this.template.jslib||{},this.template.jslib.rollup=function(){"use strict";var t={version:"0.0.1",name:"template.jslib.rollup"};return t}();

‎dist/template.jslib.rollup.umd.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3+
typeof define === 'function' && define.amd ? define(factory) :
4+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, (global.template = global.template || {}, global.template.jslib = global.template.jslib || {}, global.template.jslib.rollup = factory()));
5+
}(this, (function () { 'use strict';
6+
7+
var name = "template.jslib.rollup";
8+
var version = "0.0.1";
9+
10+
/*!
11+
* @createDate 2021-08-23
12+
*/
13+
var jsUtils = {};
14+
jsUtils.version = version;
15+
jsUtils.name = name;
16+
17+
return jsUtils;
18+
19+
})));

‎dist/template.jslib.rollup.umd.min.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
3+
版本所有
4+
填写日期
5+
填写作者信息 */
6+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).template=e.template||{},e.template.jslib=e.template.jslib||{},e.template.jslib.rollup=t())}(this,function(){"use strict";var e={version:"0.0.1",name:"template.jslib.rollup"};return e});

‎package-lock.json

+3,509
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "template.jslib.rollup",
3+
"version": "0.0.1",
4+
"description": "template js lib rollup",
5+
"main": "rollup.config.js",
6+
"scripts": {
7+
"build": "rollup -c -w",
8+
"rollup:dev": "rollup -c -w",
9+
"rollup:build": "rollup -c",
10+
"eslint": "",
11+
"test": "echo \"Error: no test specified\" && exit 1"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/MShineRay/template-jslib-rollup.git"
16+
},
17+
"keywords": [
18+
"template-jslib-rollup"
19+
],
20+
"author": "mshineray",
21+
"license": "MIT",
22+
"bugs": {
23+
"url": "https://github.com/MShineRay/template-jslib-rollup/issues"
24+
},
25+
"homepage": "https://github.com/MShineRay/template-jslib-rollup#readme",
26+
"devDependencies": {
27+
"@babel/core": "^7.15.0",
28+
"@babel/preset-env": "^7.15.0",
29+
"@rollup/plugin-babel": "^5.3.0",
30+
"@rollup/plugin-commonjs": "^20.0.0",
31+
"@rollup/plugin-json": "^4.1.0",
32+
"@rollup/plugin-node-resolve": "^13.0.4",
33+
"babel-plugin-external-helpers": "^6.22.0",
34+
"babel-plugin-lodash": "^3.3.4",
35+
"babel-preset-latest": "^6.24.1",
36+
"rollup": "^2.56.2",
37+
"rollup-plugin-eslint": "^7.0.0",
38+
"rollup-plugin-uglify": "^6.0.4"
39+
}
40+
}

‎rollup.config.js

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* @reference https://www.rollupjs.com/guide/introduction/
3+
*/
4+
import commonjs from '@rollup/plugin-commonjs'// 用来将 CommonJS 转换成 ES2015 模块的
5+
import json from '@rollup/plugin-json'
6+
import resolve from '@rollup/plugin-node-resolve'// 告诉 Rollup 如何查找外部模块
7+
import babel from '@rollup/plugin-babel'
8+
import {uglify} from 'rollup-plugin-uglify'
9+
import {name, version, author} from './package.json'
10+
const banner = `/*!
11+
* ${name} v${version}
12+
* (c) ${new Date().getFullYear()} ${author}
13+
* @license MIT
14+
*/`
15+
export default {
16+
input: 'src/index.js',
17+
output: [
18+
{
19+
banner,
20+
file: `dist/${name}.amd.js`,
21+
format: 'amd', // 浏览器
22+
name
23+
},
24+
{
25+
file: `dist/${name}.cjs.js`,
26+
format: 'cjs', // compile to a CommonJS module ('cjs') node环境
27+
name
28+
},
29+
{
30+
file: `dist/${name}.esm.js`,
31+
format: 'esm', // 浏览器
32+
name
33+
},
34+
{
35+
file: `dist/${name}.iife.js`,
36+
format: 'iife', // 浏览器
37+
name
38+
},
39+
{
40+
file: `dist/${name}.umd.js`,
41+
format: 'umd', // UMD format requires a bundle name 浏览器和 Node.js
42+
name
43+
},
44+
// min
45+
{
46+
file: `dist/${name}.amd.min.js`,
47+
format: 'amd', // 浏览器
48+
name,
49+
plugins: [uglify()]
50+
},
51+
{
52+
file: `dist/${name}.cjs.min.js`,
53+
format: 'cjs', // compile to a CommonJS module ('cjs') node环境
54+
name,
55+
plugins: [uglify()]
56+
},
57+
{
58+
file: `dist/${name}.esm.min.js`,
59+
format: 'esm', // 浏览器
60+
name,
61+
plugins: [uglify()]
62+
},
63+
{
64+
file: `dist/${name}.iife.min.js`,
65+
format: 'iife', // 浏览器
66+
name,
67+
plugins: [uglify({
68+
output:{
69+
comments: function (node, comment){
70+
//以!开头部分的注视进行保留
71+
return /^!/.test(comment.value)
72+
}
73+
}
74+
})]
75+
},
76+
{
77+
file: `dist/${name}.umd.min.js`,
78+
format: 'umd', // UMD format requires a bundle name 浏览器和 Node.js
79+
name,
80+
plugins: [uglify({
81+
output:{
82+
preamble: '/** \r\r 版本所有 \r\n 填写日期 \r\n 填写作者信息 */'
83+
}
84+
})]
85+
}
86+
],
87+
plugins: [
88+
commonjs(),
89+
json(),
90+
resolve({
91+
// 将自定义选项传递给解析插件
92+
customResolveOptions: {
93+
moduleDirectory: 'node_modules'
94+
}
95+
}),
96+
babel({
97+
// 为避免编译三方脚本,通过设置exclude属性忽略node_modules目录。
98+
// babelHelpers:'bundled',
99+
exclude: ['node_modules/**', 'dist/**', 'test/**'], // 只编译我们的源代码
100+
include: ['src/**']
101+
}),
102+
// default
103+
// ["lodash"],
104+
// Set plugin options using an array of [pluginName, optionsObject].
105+
// ["lodash", { "id": "lodash-compat", "cwd": "some/path" }]
106+
// The options.id can be an array of ids.
107+
['lodash', {id: ['async', 'lodash-bound']}],
108+
109+
// uglify() //只生产压缩的库
110+
],
111+
// 指出应将哪些模块视为外部模块:
112+
// 你可以微调哪些导入是想要打包的,哪些是外部的引用(externals)。
113+
// 对于这个例子,我们认为 lodash 是外部的引用(externals),而不是 the-answer 。
114+
external: ['lodash'],
115+
watch: {
116+
// 限制文件监控至某些文件:
117+
include: 'src/**',
118+
// 防止文件被监控:
119+
exclude: 'node_modules/**'
120+
},
121+
// treeshake: true,
122+
presets: [['@babel/env', {targets: {node: 6}}]]
123+
}

‎src/.babelrc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"plugins": ["lodash"],
3+
"presets": [
4+
[
5+
"@babel/preset-env",
6+
{
7+
"targets": {
8+
"browsers": "last 10 versions, > 1%, ie >= 9, Android >= 4.4, iOS >= 8",
9+
"node": "current"
10+
},
11+
"modules": false,
12+
"useBuiltIns": false
13+
}
14+
]
15+
]
16+
}

‎src/ajax.js

Whitespace-only changes.

‎src/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*!
2+
* @createDate 2021-08-23
3+
*/
4+
import version from './version'
5+
import name from './name'
6+
const jsUtils = {}
7+
jsUtils.version = version
8+
jsUtils.name = name
9+
export default jsUtils

‎src/name.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* name
3+
* @desc
4+
*/
5+
import { name } from '../package.json'
6+
export default name

‎src/version.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* version
3+
* @desc
4+
*/
5+
import { version } from '../package.json'
6+
export default version

0 commit comments

Comments
 (0)
Please sign in to comment.