Skip to content

Commit

Permalink
perf: 并发打包
Browse files Browse the repository at this point in the history
  • Loading branch information
MuYunyun committed Sep 6, 2018
1 parent 1313e9e commit 208ca77
Show file tree
Hide file tree
Showing 19 changed files with 561 additions and 830 deletions.
6 changes: 0 additions & 6 deletions .babelrc

This file was deleted.

3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ snippets
.gitignore
karma.conf.js
tag_database
bower.json
bower.json
dist
2 changes: 1 addition & 1 deletion README-zh_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![npm version](https://badge.fury.io/js/diana.svg)](https://badge.fury.io/js/diana) [![week download](https://img.shields.io/npm/dw/diana.svg)](https://www.npmjs.com/package/diana) ![Build Status](https://travis-ci.org/MuYunyun/diana.svg?branch=master) [![codecov](https://codecov.io/gh/MuYunyun/diana/branch/master/graph/badge.svg)](https://codecov.io/gh/MuYunyun/diana) ![LICENSE MIT](https://img.shields.io/npm/l/express.svg)

A lightweight tool library (Support for `browser` and `node` environment)
A lightweight fe tool library

### Installation

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<img src="http://oqhtscus0.bkt.clouddn.com/dcce7b9509a0e23f91d8cd2aa3ecffd3.jpg-200">
</div>

![Build Status](https://travis-ci.org/MuYunyun/diana.svg?branch=master) [![codecov](https://codecov.io/gh/MuYunyun/diana/branch/master/graph/badge.svg)](https://codecov.io/gh/MuYunyun/diana) ![LICENSE MIT](https://img.shields.io/npm/l/express.svg)
[![npm version](https://badge.fury.io/js/diana.svg)](https://badge.fury.io/js/diana) [![week download](https://img.shields.io/npm/dw/diana.svg)](https://www.npmjs.com/package/diana) ![Build Status](https://travis-ci.org/MuYunyun/diana.svg?branch=master) [![codecov](https://codecov.io/gh/MuYunyun/diana/branch/master/graph/badge.svg)](https://codecov.io/gh/MuYunyun/diana) ![LICENSE MIT](https://img.shields.io/npm/l/express.svg)

轻量级定制化工具库(支持 `browser``node` 环境)
前端定制化工具库

* 支持 browser 和 node 环境

### Install

Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<header class="height">
<h1 class="logo" href="https://github.com/MuYunyun/diana">
<span id="title">&nbsp;Diana</span>
<small>前端业务代码归纳库</small>
<small>前端定制化工具库</small>
</h1>
<label for="doc-drawer-checkbox" class="button drawer-toggle" id="menu-toggle"></label>
</header>
Expand Down
2 changes: 1 addition & 1 deletion docs/static-parts/index-start.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<header class="height">
<h1 class="logo" href="https://github.com/MuYunyun/diana">
<span id="title">&nbsp;Diana</span>
<small>前端业务代码归纳库</small>
<small>前端定制化工具库</small>
</h1>
<label for="doc-drawer-checkbox" class="button drawer-toggle" id="menu-toggle"></label>
</header>
Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = function(config) {
},

webpack: {
mode: 'development',
devtool: 'inline-source-map',
module: {
rules: [{
Expand Down
17 changes: 16 additions & 1 deletion lib/diana.back.js

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion lib/diana.js

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
{
"name": "diana",
"version": "0.4.5",
"version": "0.4.6",
"description": "fe tool library",
"browser": "lib/diana.js",
"main": "lib/diana.back.js",
"dependencies": {},
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^10.5.4",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"chalk": "^2.3.0",
"codecov": "^3.0.0",
"diana": "^0.4.2",
"diana": "^0.4.5",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
Expand All @@ -33,7 +30,7 @@
"tslint": "^5.11.0",
"typescript": "^2.9.2",
"watchify": "^3.9.0",
"webpack": "^3.10.0"
"webpack": "^4.17.2"
},
"scripts": {
"build": "node script/build.js",
Expand Down
41 changes: 27 additions & 14 deletions script/build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require('path')
const fs = require('fs')
const ora = require('ora')
const rm = require('rimraf')
const chalk = require('chalk')
Expand All @@ -11,27 +10,28 @@ const pkg = require('../package.json')
const rootPath = path.resolve(__dirname, '../')

let building = ora('building...')
new Promise((resolve, reject) => {
building.start()
rm(path.resolve(rootPath, 'lib', `${pkg.name}.back.js`), err => {
if (err) throw {err}
webpack(nodeConfig, (err, stats) => { // https://webpack.js.org/api/compiler/ 构建 node 端压缩包

async function buildNode() {
await rm(path.resolve(rootPath, 'lib', `${pkg.name}.back.js`), err => {
if (err) throw { err }
webpack(nodeConfig, (err, stats) => { // https://webpack.js.org/api/compiler/
if (err) throw err
process.stdout.write(stats.toString({
colors: true, // Shows colors in the console
colors: true, // Shows colors in the console
chunks: false, // Makes the build much quieter
modules: false,
children: false,
chunkModules: false
}) + '\n\n')
resolve()
console.log(chalk.cyan(' NodeFn Build complete.\n'))
})
})
}).then(() => {
rm(path.resolve(rootPath, 'lib', `${pkg.name}.js`), err => {
}

async function buildBrowser() {
await rm(path.resolve(rootPath, 'lib', `${pkg.name}.js`), err => {
if (err) throw { err }
webpack(bsConfig, (err, stats) => { // 构建浏览器端压缩包
webpack(bsConfig, (err, stats) => {
if (err) throw err
building.stop()
process.stdout.write(stats.toString({
Expand All @@ -44,6 +44,19 @@ new Promise((resolve, reject) => {
console.log(chalk.cyan(' BrowserFn Build complete.\n'))
})
})
}).catch((err) => {
throw err
})
}

async function build() {
building.start()
Promise.all([
await buildNode(),
await buildBrowser()
]).then(([result1, result2]) => {
building.stop()
}).catch(e => {
building.stop()
throw e
})
}

build()
17 changes: 3 additions & 14 deletions script/webpack.browser.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
const webpack = require('webpack')
const path = require('path')

const pkg = require('../package.json')

const rootPath = path.resolve(__dirname, '../')

const config = {
entry: path.resolve(rootPath, 'dist/src/browser', 'index.js'),
mode: "production",
output: {
filename: `${pkg.name}.js`,
path: path.resolve(rootPath, 'lib'),
library: `${pkg.name}`,
libraryTarget: 'umd' // http://www.imooc.com/article/10969
},
module: {
rules: [{
test: /\.js$/,
loader: "babel-loader",
}]
},
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
libraryTarget: 'umd'
}
}

module.exports = config
16 changes: 3 additions & 13 deletions script/webpack.node.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
const webpack = require('webpack')
const path = require('path')

const pkg = require('../package.json')

const rootPath = path.resolve(__dirname, '../')

const config = {
entry: path.resolve(rootPath, 'dist/src/node', 'index.js'),
mode: "production",
output: {
filename: `${pkg.name}.back.js`,
path: path.resolve(rootPath, 'lib'),
library: `${pkg.name}`,
libraryTarget: 'umd' // http://www.imooc.com/article/10969
},
module: {
rules: [{
test: /\.js$/,
loader: "babel-loader",
}]
},
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
libraryTarget: 'umd'
}
}

module.exports = config
14 changes: 13 additions & 1 deletion src/common/collection/each.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import { optimizeCb } from '../../util'
// 拱其它函数使用,返回一个回调函数
const optimizeCb = function (func: any, context: any, argCount?: any) {
if (context === void 0) return func
switch (argCount) {
case 1: return (value: any) => {
return func.call(context, value)
}
}
return (...args: Array<any>) => {
return func.apply(context, args)
}
}

// https://github.com/jashkenas/underscore/pull/2094
const MAX_ARRAY_INDEX = Math.pow(2, 53) - 1
/**
Expand Down
5 changes: 4 additions & 1 deletion src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const fn = {
timeTaken,
}

const commonFn = Object.assign({}, fn, typeObj)
const commonFn = {
...fn,
...typeObj,
}

export = commonFn
14 changes: 0 additions & 14 deletions src/util.ts

This file was deleted.

10 changes: 9 additions & 1 deletion test/browser/device.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('#Device API:', () => {
it(`_.getOS() should return "MacOSX"`, () => {
let os = _.getOS()
if (os === 'Linux') {
os = 'MacOSX' // 这里只是为了骗过 travis-ci(Linux) 的验证
os = 'MacOSX' // 绕过 travis-ci(Linux) 的验证
}
assert.equal(os, 'MacOSX')
})
Expand All @@ -16,4 +16,12 @@ describe('#Device API:', () => {
assert.equal(_.isMobile(), false)
})
})
})

describe('#tmp API:', () => { // it's is a template code
describe('#sum()', () => {
it(`_.sum([1, 2, 3, 4]) should return 10`, () => {
assert.equal(_.sum([1, 2, 3, 4]), 10)
})
})
})
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"exclude": [],
"compilerOptions": {
"module": "commonjs",
"outDir": "./dist/",
"alwaysStrict": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"sourceMap": true,
"inlineSources": true,
"target": "es5",
Expand All @@ -24,6 +24,7 @@
],
},
"include": [
"test/"
"test/",
"src",
]
}
Loading

0 comments on commit 208ca77

Please sign in to comment.