Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump websocket-extensions from 0.1.3 to 0.1.4 #10

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": ["es2015"],
"plugins": ["transform-runtime"],
"comments": false
}
30 changes: 30 additions & 0 deletions .config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
[name].js // umd 未压缩
[name].min.js // umd 压缩
[name].cmd.js // 已压缩 加 warning
[name].mui.js // 已压缩,配置后还会额外生成 seed.json 和 seed.js
[name].common.js // 不压缩
*/

'user strict'
const pkg = require('../package.json')
// 默认模块名取 package.js 的 name,但有特殊需求,需要声明 package.name 和包名不一致,使用 x-name
const name = pkg['x-name'] || pkg.name
const outputPath = 'dist'
module.exports = {
name: name,
outputPath: outputPath,
entry: 'src/index.js',
output: `${outputPath}/${name}.js`,
outputMin: `${outputPath}/${name}.min.js`,
outputCommon: `${outputPath}/${name}.common.js`,
outputEs: `${outputPath}/${name}.es.js`,
// outputCmd: `${outputPath}/${name}.cmd.js`,
// outputMui: `${outputPath}/${name}.mui.js`,
browser: 'test/browser.js',
nodeResolve: true, // 是否把 node_modules 中的 js 也 inline, 默认 true
autoprefixer: {
browsers: ['Android >= 4', 'iOS >= 7', 'IE >= 9', 'Firefox >= 50', 'Chrome >= 21']
}
// px2rem: {remUnit: 100, baseDpr: 1} // 开启后需在页面中加入 `!function (t) {t.style.fontSize = t.getBoundingClientRect().width / 3.75 + 'px'}(document.documentElement)`
}
182 changes: 182 additions & 0 deletions .config/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { getConfig, getGzipSize, red, blue, write, uglify, camelize } from './util'
import postcss from 'postcss'
import autoprefixer from 'autoprefixer'
import px2rem from 'postcss-px2rem'
import vue from 'rollup-plugin-vue'
import less from 'rollup-plugin-less'
import buble from 'rollup-plugin-buble'
import replace from 'rollup-plugin-replace'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import pkg from '../package.json'
const rollup = require('rollup')

process.env.NODE_ENV = 'production'

class Build {
constructor () {
this.config = getConfig(require('./index'), pkg)
this.banner =
`/*!
* ${this.config.name} v${pkg.version}
* (c) ${new Date().getFullYear()} ${pkg.contributors.join(' ')}
* Released under the ${pkg.license} License.
*/`
this._rollupConfig = {
entry: this.config.entry,
plugins: [
this.config.nodeResolve && nodeResolve({
jsnext: true,
main: true
}),
this.config.nodeResolve && commonjs({
include: 'node_modules/**',
extensions: [ '.js', '.coffee' ],
ignoreGlobal: false,
sourceMap: false
}),

replace({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),

vue({
compileTemplate: false,
css: this.config.output_css,
htmlMinifier: {
minifyCSS: true,
minifyJS: true,
collapseBooleanAttributes: true,
collapseWhitespace: true,
decodeEntities: true,

html5: true,
processConditionalComments: true,
processScripts: [
'text/html'
],
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeTagWhitespace: true,
useShortDoctype: true
}
}),

less({
insert: false,
output: this.config.output_css
}),

postcss([
autoprefixer(this.config.autoprefixer),
this.config.px2rem && px2rem(this.config.px2rem)
].filter(Boolean)),

buble()
].filter(Boolean)
}
}

async run () {
try {
const bundle = await rollup.rollup(this._rollupConfig)
await Promise.all([
this.genCommon(bundle),
this.genUmd(bundle),
this.genEs(bundle)
])
await Promise.all([
this.genMin(this.umd),
this.genCmd(this.common),
this.genMui(this.common)
])

if (this.config.outputMin) {
const size = await getGzipSize(this.config.outputMin)
console.log(red('gzip:') + ' ' + blue(size))
}
} catch (e) {
console.error(red(e))
}
}

async genCommon (bundle) {
this.common = bundle.generate({
banner: this.banner,
useStrict: false,
format: 'cjs'
}).code
this.config.outputCommon && await write(this.config.outputCommon, this.common)
}

async genUmd (bundle) {
this.umd = bundle.generate({
banner: this.banner,
useStrict: false,
format: 'umd',
moduleName: camelize(this.config.name)
}).code
this.config.output && await write(this.config.output, this.umd)
}

async genEs (bundle) {
this.es = bundle.generate({
banner: this.banner,
useStrict: false,
format: 'es'
}).code
this.config.outputEs && await write(this.config.outputEs, this.es)
}

async genMin (umd) {
if (!this.config.outputMin) return
this.min = uglify(umd)
await write(this.config.outputMin, this.min)
}

async genCmd (common) {
if (!this.config.outputCmd) return
this.cmdMin = uglify(`
define('${pkg.group}/${this.config.name.toLowerCase()}/${pkg.version}/index.cmd.js', function(require, exports, module) {
${common}
})
`)
await write(this.config.outputCmd, this.cmdMin)
}

async genMui (common) {
if (!this.config.outputMui) return
const dName = `${pkg.group}/${this.config.name.toLowerCase()}`
this.muiMin = uglify(`
define('${dName}/index.mui', function(require, exports, module) {
${common}
})
`)
let seed = {
combine: true,
modules: {},
packages: {
[dName]: {
debug: true,
group: 'tm',
ignorePackageNameInUri: true,
path: `//g.alicdn.com/${dName}/${pkg.version}/`,
version: pkg.version
}
}
}

await Promise.all([
write(this.config.outputMui, this.muiMin),
write(`${this.config.outputPath}/seed.json`, JSON.stringify(seed)),
write(`${this.config.outputPath}/seed.js`, uglify(`KISSY.config(${JSON.stringify(seed)})`))
])
}
}

new Build().run()
66 changes: 66 additions & 0 deletions .config/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import fs from 'fs'
import path from 'path'
import Uglify from 'uglify-js'
import gzipSize from 'gzip-size'

export function getConfig () {
const userConfig = require('./index')
return userConfig
}

export function getSize (code) {
return `${(code.length / 1024).toFixed(2)}kb`
}

export function blue (str) {
return `\x1b[1m\x1b[34m${String(str)}\x1b[39m\x1b[22m`
}

export function red (str) {
return `\x1b[1m\x1b[31m${String(str)}\x1b[39m\x1b[22m`
}

export function camelize (str) {
return str.replace(/[_.-](\w|$)/g, function (_, x) {
return x.toUpperCase()
})
}

export function getGzipSize (path) {
return read(path).then(string => {
return `${(gzipSize.sync(string) / 1024).toFixed(2)}kb`
})
}

export function write (dest, code) {
const projectRoot = path.resolve(__dirname, '../')
dest = path.resolve(projectRoot, dest)
return new Promise((resolve, reject) => {
fs.writeFile(dest, code, err => {
if (err) {
console.error(red(JSON.stringify(err, null, 2)))
return reject(err)
}
console.log(`${blue(dest)} ${getSize(code)}`)
resolve()
})
})
}

export function read (dest, code) {
const projectRoot = path.resolve(__dirname, '../')
dest = path.resolve(projectRoot, dest)
return new Promise((resolve, reject) => {
fs.readFile(dest, 'utf8', (err, data) => {
if (err) {
console.error(red(JSON.stringify(err, null, 2)))
reject(err)
}
resolve(data)
})
})
}

export function uglify (code) {
return Uglify.minify(code).code
}
67 changes: 67 additions & 0 deletions .config/webpack.base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict'
const path = require('path')
const nodeDir = path.resolve(__dirname, '../node_modules')
const projectRoot = path.resolve(__dirname, '../')
const autoprefixer = require('autoprefixer')
const webpack = require('webpack')
const px2rem = require('postcss-px2rem')
const config = require('./index')

module.exports = {
entry: './' + config.browser,
output: {
filename: './' + config.browser
},
resolve: {
extensions: ['', '.js', '.vue'],
root: path.resolve('../src'),
alias: {
vue: path.resolve(nodeDir, 'vue/dist/vue.js'),
vuex: path.resolve(nodeDir, 'vuex/dist/vuex.js')
}
},
module: {
preLoaders: [
{
test: /\.vue$/,
loader: 'eslint',
include: projectRoot,
exclude: /node_modules/
},
{
test: /\.js$/,
loader: 'eslint',
include: projectRoot,
exclude: /node_modules/
}
],
loaders: [{
test: /\.vue$/,
loader: 'vue'
}, {
test: /\.js$/,
loader: 'rollup',
exclude: /node_modules/
}, {
test: /\.less$/,
loader: 'style!css?sourceMap!postcss!less?strictMath&noIeCompat&sourceMap'
}]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
],
rollup: [
require('rollup-plugin-buble')({
exclude: 'node_modules/**'
})
],
eslint: {
formatter: require('eslint-friendly-formatter')
},
postcss: [
config.autoprefixer && autoprefixer(config.autoprefixer),
config.px2rem && px2rem(config.px2rem)
].filter(Boolean)
}
20 changes: 20 additions & 0 deletions .config/webpack.dev.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'
const config = require('./webpack.base.config')
const merge = require('webpack-merge')
const WebpackNotifierPlugin = require('webpack-notifier')
const pkg = require('../package.json')

module.exports = merge(config, {
devtool: 'eval-source-map',
plugins: [
new WebpackNotifierPlugin({
title: `${pkg.name}@${pkg.version}`,
excludeWarnings: true,
contentImage: `${__dirname}/logo.png`
})
],
babel: {
presets: ['es2015'],
plugins: ['typecheck', 'transform-flow-strip-types', 'transform-runtime']
}
})
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
Loading