1
0
mirror of synced 2025-12-08 14:54:02 +08:00

chore: reduce size

This commit is contained in:
surunzi
2020-01-07 22:24:47 +08:00
parent 7dcdfe2c9a
commit 8323486987
6 changed files with 144 additions and 4 deletions

View File

@@ -1778,6 +1778,21 @@ Check if value is a regular expression.
isRegExp(/a/); // -> true
```
## isSorted
Check if an array is sorted.
|Name |Type |Desc |
|------|--------|-----------------------|
|arr |array |Array to check |
|[cmp] |function|Comparator |
|return|boolean |True if array is sorted|
```javascript
isSorted([1, 2, 3]); // -> true
isSorted([3, 2, 1]); // -> false
```
## isStr
Check if value is a string primitive.
@@ -2378,6 +2393,29 @@ some([2, 5], function (val) {
}); // -> true
```
## sortKeys
Sort keys of an object.
|Name |Type |Desc |
|-------|------|-----------------------|
|obj |object|Object to sort |
|options|object|Sort options |
|return |object|Object with sorted keys|
Available options:
|Name |Type |Desc |
|------------|--------|---------------------|
|deep=false |boolean |Sort keys recursively|
|[comparator]|function|Comparator |
```javascript
sortKeys({b: {d: 2, c: 1}, a: 0}, {
deep: true
}); // -> {a: 0, b: {c: 1, d: 2}}
```
## splitCase
Split different string case to an array.

View File

@@ -0,0 +1,12 @@
const cssMap = require('../../src/lib/cssMap')
const escapeRegExp = require('licia/escapeRegExp')
const each = require('licia/each')
module.exports = function (src) {
each(cssMap, (val, key) => {
src = src.replace(new RegExp(escapeRegExp(';' + key + ':'), 'g'), ';$' + val + ':')
src = src.replace(new RegExp(escapeRegExp('{' + key + ':'), 'g'), '{$' + val + ':')
})
return src
}

View File

@@ -0,0 +1,3 @@
module.exports = function (src) {
return src.replace(/"loc":\{"start":\{"line":\d+,"column":\d+},"end":\{"line":\d+,"column":\d+\}\}/g, '')
}

View File

@@ -24,6 +24,11 @@ const postcssLoader = {
}
}
const cssMinifierLoader = {
loader: path.resolve(__dirname, './loaders/css-minifier-loader'),
options: {}
}
module.exports = {
entry: './src/index',
devServer: {
@@ -54,20 +59,31 @@ module.exports = {
},
{
test: /\.scss$/,
loaders: ['css-loader', postcssLoader, 'sass-loader']
loaders: [cssMinifierLoader, 'css-loader', postcssLoader, 'sass-loader']
},
{
test: /\.css$/,
loaders: ['css-loader', postcssLoader]
loaders: [cssMinifierLoader, 'css-loader', postcssLoader]
},
// https://github.com/wycats/handlebars.js/issues/1134
{
test: /\.hbs$/,
use: [
{
loader: path.resolve(
__dirname,
'./loaders/handlebars-minifier-loader.js'
),
options: {}
},
{
loader: nodeModDir + 'handlebars-loader/index.js',
options: {
runtime: srcDir + 'lib/handlebars.js'
runtime: srcDir + 'lib/handlebars.js',
knownHelpers: ['class', 'repeat', 'concat'],
precompileOptions: {
knownHelpersOnly: true
}
}
},
{

55
src/lib/cssMap.js Normal file
View File

@@ -0,0 +1,55 @@
module.exports = {
background: 'b',
'background-image': 'bi',
border: 'bo',
'border-bottom': 'bb',
'border-collapse': 'bc',
'border-left-color': 'blc',
'border-right': 'br',
'border-radius': 'bra',
'border-top': 'bt',
'border-top-color': 'btc',
'box-shadow': 'bs',
'box-sizing': 'bsi',
clear: 'cl',
color: 'c',
content: 'co',
cursor: 'cu',
display: 'd',
flex: 'fl',
'flex-shrink': 'fsh',
float: 'f',
'font-family': 'ff',
'font-size': 'fs',
'font-weight': 'fw',
height: 'h',
left: 'l',
'line-height': 'lh',
margin: 'm',
'margin-bottom': 'mb',
'margin-left': 'ml',
'margin-top': 'mt',
'min-height': 'mh',
outline: 'ou',
overflow: 'o',
'overflow-x': 'ox',
'overflow-y': 'oy',
padding: 'p',
'padding-bottom': 'pb',
'padding-left': 'pl',
'padding-top': 'pt',
'pointer-events': 'pe',
position: 'po',
'text-align': 'ta',
'text-transform': 'tt',
top: 't',
transition: 'tr',
'user-select': 'us',
'vertical-aligin': 'va',
visibility: 'v',
width: 'w',
'will-change': 'wc',
'white-space': 'ws',
'-webkit-overflow-scrolling': 'wos',
'z-index': 'z'
}

View File

@@ -1,5 +1,15 @@
import { toStr, each, filter, isStr, keys, kebabCase, defaults } from './util'
import {
toStr,
each,
filter,
isStr,
keys,
kebabCase,
defaults,
escapeRegExp
} from './util'
import themes from './themes'
import cssMap from './cssMap'
let styleList = []
let scale = 1
@@ -63,6 +73,12 @@ function resetStyles() {
function resetStyle({ css, el }) {
css = css.replace(/(\d+)px/g, ($0, $1) => +$1 * scale + 'px')
css = css.replace(/_/g, 'eruda-')
each(cssMap, (val, key) => {
css = css.replace(
new RegExp(escapeRegExp(`$${val}:`), 'g'),
';' + key + ':'
)
})
const _keys = keys(themes.Light)
each(_keys, key => {
css = css.replace(