Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src | ||
test | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# @wepy/plugin-file-min 插件 | ||
|
||
## 安装 | ||
|
||
```bash | ||
npm install @wepy/plugin-file-min --save-dev | ||
``` | ||
## 配置`wepy.config.js` | ||
```javascript | ||
const FileMinPlugin = require('@wepy/plugin-file-min') | ||
// 在末尾添加: | ||
module.exports.plugins.push(FileMinPlugin()) | ||
// 关闭压缩功能: | ||
module.exports.plugins.push(FileMinPlugin({ enable: false })) | ||
``` | ||
或者根据你配置的环境变量来判断: | ||
```javascript | ||
const isCompress = process.env.COMPRESS === 'compress'; | ||
if (isCompress) { | ||
module.exports.plugins.push(FileMinPlugin({})) | ||
} | ||
``` | ||
## 参数说明 | ||
你提供的配置选项 ```options``` 的 enable 字段 用于配置否关闭压缩功能。默认为开启 | ||
内部默认配置如下: | ||
```javascript | ||
let options = { | ||
enable: true, | ||
wxml: true, | ||
json: true, | ||
// 默认不压缩 wxss, 因为大部分开发者有用 less 或 sass 插件, 已经压缩过了 wxss。 | ||
wxss: false | ||
} | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@wepy/plugin-filemin", | ||
"version": "1.3.13", | ||
"description": "wepy filemin plugin", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/wepy/packages/@wepy/plugin-file-min" | ||
}, | ||
"keywords": [ | ||
"filemin", | ||
"wepy", | ||
"wepy2.0", | ||
"compress", | ||
"wxml", | ||
"json" | ||
], | ||
"author": "hdzattain", | ||
"license": "MIT", | ||
"dependencies": { | ||
"pretty-data": "^0.40.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const _prettyData = require('pretty-data') | ||
|
||
function FileMinPlugin(options = {}) { | ||
return function () { | ||
let config = { | ||
enable: true, | ||
wxml: true, | ||
json: true, | ||
wxss: false | ||
} | ||
config = Object.assign(config, options) | ||
this.register('build-components', comps => { | ||
if (!config.enable) { | ||
return comps | ||
} | ||
let t = null | ||
let c = null | ||
for (let i = 0, len = comps.length; i < len; i++) { | ||
t = comps[i].sfc.template | ||
c = comps[i].sfc.config | ||
if (config.wxml && /^(wxml|xml)$/.test(t.lang)) { | ||
t.outputCode = _prettyData.pd.xmlmin(t.outputCode) | ||
} | ||
if (config.json && /^json$/.test(c.lang)) { | ||
c.outputCode = _prettyData.pd.jsonmin(c.outputCode) | ||
} | ||
if (config.wxss && /^wxss$/.test(c.lang)) { | ||
c.outputCode = _prettyData.pd.cssmin(c.outputCode) | ||
} | ||
} | ||
return comps | ||
}) | ||
this.register('build-apps', apps => { | ||
if (!config.enable) { | ||
return apps | ||
} | ||
let t = null | ||
let c = null | ||
for (let i = 0, len = apps.length; i < len; i++) { | ||
t = apps[i].sfc.template | ||
c = apps[i].sfc.config | ||
if (config.wxml && /^(wxml|xml)$/.test(t.lang)) { | ||
t.outputCode = _prettyData.pd.xmlmin(t.outputCode) | ||
} | ||
if (config.json && /^json$/.test(c.lang)) { | ||
c.outputCode = _prettyData.pd.jsonmin(c.outputCode) | ||
} | ||
if (config.wxss && /^wxss$/.test(c.lang)) { | ||
c.outputCode = _prettyData.pd.cssmin(c.outputCode) | ||
} | ||
} | ||
return apps | ||
}) | ||
this.register('build-vendors', vendors => { | ||
if (!config.enable) { | ||
return vendors | ||
} | ||
let t = null | ||
let c = null | ||
for (let i = 0, len = vendors.length; i < len; i++) { | ||
t = vendors[i].sfc.template | ||
c = vendors[i].sfc.config | ||
if (config.wxml && /^(wxml|xml)$/.test(t.lang)) { | ||
t.outputCode = _prettyData.pd.xmlmin(t.outputCode) | ||
} | ||
if (config.json && /^json$/.test(c.lang)) { | ||
c.outputCode = _prettyData.pd.jsonmin(c.outputCode) | ||
} | ||
if (config.wxss && /^wxss$/.test(c.lang)) { | ||
c.outputCode = _prettyData.pd.cssmin(c.outputCode) | ||
} | ||
} | ||
return vendors | ||
}) | ||
} | ||
} | ||
|
||
module.exports = FileMinPlugin |