Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a18171b
first commit
Aug 11, 2016
d5b3c95
rm dependencies
Aug 11, 2016
de9ee4b
add zero-width-space
Aug 11, 2016
b4de38b
add .travis.yml
Aug 11, 2016
6172d3b
add travis ico
Aug 11, 2016
67ee514
unique
Aug 11, 2016
b28b423
add babel-preset-es2015
Aug 13, 2016
de81926
add Dependency Status
Aug 13, 2016
cd14b6f
update link
Aug 16, 2016
f7085a1
1.0.5
Aug 16, 2016
6b61a5d
add ci node version
Aug 16, 2016
7c264a7
1.0.6
Aug 24, 2016
5d467ed
update devDependencies
Sep 28, 2016
3c90cbc
update devDependencies
Sep 28, 2016
4e7c4c9
update devDependencies
Sep 28, 2016
40bc161
update devDependencies
Sep 28, 2016
16f8af7
update devDependencies
Sep 28, 2016
f52d4ff
update devDependencies
Sep 28, 2016
0e2ab6d
update devDependencies
Nov 22, 2016
f2fb8e4
update devDependencies
haozi Dec 12, 2016
7afbdf0
update devDependencies
haozi Dec 12, 2016
c2092b9
update devDependencies
haozi Dec 12, 2016
1ab54c7
update travis
haozi Dec 12, 2016
2355d03
happy new year
haozi Jan 11, 2017
f8442af
update
haozi Feb 3, 2017
8b2522a
update
haozi Feb 3, 2017
ddc91be
update
Apr 11, 2017
4dd2a54
add es module
Apr 17, 2017
746bebc
add es module
haozi Apr 17, 2017
c101e28
happy new year
haozi Jan 15, 2018
75ed828
happy new year
haozi Jan 15, 2018
191c163
update
haozi Feb 1, 2018
512a938
add: 新增零宽字符 \u202D
Jan 18, 2019
063f82f
Merge pull request #3 from jschyz/master
haozi Feb 26, 2019
533a69d
新增零宽字符 \u202D
Feb 26, 2019
b2e007a
新增零宽字符 \u202D
Feb 26, 2019
6ae4007
update package.json
Feb 26, 2019
1ef2b25
update package.json
Feb 26, 2019
6ce589a
update package.json
Feb 26, 2019
67dc47a
update package.json
Feb 26, 2019
36f5a4d
update package.json
Feb 26, 2019
d8b30c5
update travis
Feb 27, 2019
9eee2b9
update travis
Feb 27, 2019
1a2cf64
update travis
Feb 27, 2019
5681170
Bump js-yaml from 3.12.1 to 3.13.1
dependabot[bot] Feb 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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