-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-uglifyjs): added uglifyjs plugin
- Loading branch information
Showing
5 changed files
with
94 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 @@ | ||
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,27 @@ | ||
# wepy uglifyjs 插件 | ||
|
||
## 安装 | ||
|
||
```bash | ||
npm install @wepy/plugin-uglifyjs uglify-js --save-dev | ||
``` | ||
|
||
## 配置`wepy.config.js` | ||
|
||
```javascript | ||
const PluginUglifyjs = require('@wepy/plugin-uglifyjs'); | ||
|
||
module.exports = { | ||
plugins: [ | ||
PluginUglifyjs({ | ||
// options | ||
}) | ||
] | ||
}; | ||
``` | ||
|
||
## 参数说明 | ||
|
||
你提供的配置选项 ```options``` 将传递给 ```UglifyJS```处理,有关 ```options``` 的更多详细信息,请参阅[UglifyJS文档](https://github.com/mishoo/UglifyJS2#minify-options)。 | ||
|
||
|
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,45 @@ | ||
/** | ||
* Tencent is pleased to support the open source community by making WePY available. | ||
* Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
const UglifyJS = require('uglify-js'); | ||
|
||
exports = module.exports = function (options = {}) { | ||
return function () { | ||
this.register('output-file', function ({ filename, code, encoding }) { | ||
|
||
let ext = path.extname(filename); | ||
if (ext !== '.js') { | ||
return { filename, code, encoding }; | ||
} | ||
|
||
let result = UglifyJS.minify({ [filename]: code }, options); | ||
|
||
if (result.error) { | ||
let pos = { | ||
line: result.error.line, | ||
column: result.error.col | ||
}; | ||
throw { | ||
handler: 'script', | ||
error: { | ||
filename: result.error.filename, | ||
code: code, | ||
type: 'error', | ||
message: result.error.message, | ||
title: 'uglifyjs' | ||
}, | ||
pos: { | ||
start: pos, | ||
end: pos | ||
} | ||
}; | ||
} | ||
}); | ||
} | ||
}; |
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,20 @@ | ||
{ | ||
"name": "@wepy/plugin-uglifyjs", | ||
"version": "0.0.1", | ||
"description": "wepy uglifyjs", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"wepy", | ||
"uglifyjs" | ||
], | ||
"author": "Gcaufy", | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"uglify-js": "^3.4.9" | ||
}, | ||
"dependencies": { | ||
} | ||
} |
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 @@ | ||
// Todo |