mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2026-02-06 11:17:36 +00:00
refactor minify script
This commit is contained in:
parent
d48118b90b
commit
e664481175
6
.github/workflows/latest.yml
vendored
6
.github/workflows/latest.yml
vendored
@ -24,15 +24,15 @@ jobs:
|
||||
git pull
|
||||
- name: Minify Files
|
||||
run: |
|
||||
cd /mnt/HDD/public/.EmulatorJS/data/minify/
|
||||
cd /mnt/HDD/public/.EmulatorJS/
|
||||
npm i
|
||||
npm run build
|
||||
npm run minify
|
||||
- name: Zip Minified Files
|
||||
run: |
|
||||
cd /mnt/HDD/public/.EmulatorJS/data/
|
||||
zip emulator.min.zip emulator.min.js emulator.min.css
|
||||
- name: Clean Up Minify
|
||||
run: |
|
||||
cd /mnt/HDD/public/.EmulatorJS/data/
|
||||
cd /mnt/HDD/public/.EmulatorJS/
|
||||
rm "minify/package-lock.json"
|
||||
rm -rf "minify/node_modules/"
|
||||
7
.github/workflows/stable.yml
vendored
7
.github/workflows/stable.yml
vendored
@ -66,9 +66,4 @@ jobs:
|
||||
run: |
|
||||
cd /mnt/HDD/public/
|
||||
rm -f "$OLD_VERSION/data/emulator.min.zip"
|
||||
rm -rf "$OLD_VERSION/data/minify/node_modules/"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
rm -rf "$OLD_VERSION/node_modules/"
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,6 +1,5 @@
|
||||
**/node_modules/
|
||||
*.db
|
||||
data/minify/package-lock.json
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
roms/
|
||||
@ -8,4 +7,4 @@ data/emulator.min.js
|
||||
data/emulator.min.css
|
||||
data/cores
|
||||
.DS_Store
|
||||
.vscode/*
|
||||
.vscode/*
|
||||
|
||||
@ -88,6 +88,12 @@ npm i
|
||||
npm start
|
||||
```
|
||||
|
||||
#### Minifying
|
||||
|
||||
Before pushing the script files onto your production server it is recommended to minify them to save on load times as well as bandwidth.
|
||||
|
||||
Read the [minifying](minify/README.md) documentation for more info.
|
||||
|
||||
<br>
|
||||
|
||||
**>> When reporting bugs, please specify what version you are using**
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
const UglifyJS = require("uglify-js");
|
||||
const fs = require('fs');
|
||||
const uglifycss = require('uglifycss');
|
||||
|
||||
const scripts = [
|
||||
"emulator.js",
|
||||
"nipplejs.js",
|
||||
"shaders.js",
|
||||
"storage.js",
|
||||
"gamepad.js",
|
||||
"GameManager.js",
|
||||
"socket.io.min.js",
|
||||
"compression.js"
|
||||
];
|
||||
let code = "(function() {\n";
|
||||
for (let i=0; i<scripts.length; i++) {
|
||||
code += fs.readFileSync('../src/'+scripts[i], 'utf8') + "\n";
|
||||
}
|
||||
code += "\n})();"
|
||||
|
||||
function minify(source){
|
||||
const ast = UglifyJS.parse(source);
|
||||
return UglifyJS.minify(ast).code;
|
||||
}
|
||||
console.log('minifying');
|
||||
fs.writeFileSync('../emulator.min.css', uglifycss.processString(fs.readFileSync('../emulator.css', 'utf8')));
|
||||
fs.writeFileSync('../emulator.min.js', minify(code));
|
||||
console.log('done!');
|
||||
@ -1,22 +0,0 @@
|
||||
{
|
||||
"name": "emulatorjs-minify",
|
||||
"version": "1.0.1",
|
||||
"description": "Minify the EmulatorJS javascript files",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "node index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/EmulatorJS/EmulatorJS.git"
|
||||
},
|
||||
"author": "Ethan O'Brien",
|
||||
"bugs": {
|
||||
"url": "https://github.com/EmulatorJS/EmulatorJS/issues"
|
||||
},
|
||||
"homepage": "https://github.com/EmulatorJS/EmulatorJS#readme",
|
||||
"dependencies": {
|
||||
"uglify-js": "^3.17.4",
|
||||
"uglifycss": "0.0.29"
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,6 @@
|
||||
|
||||
# Minifying
|
||||
|
||||
Before pushing the script files onto your production <br>
|
||||
server it is recommended to minify them to save on <br>
|
||||
load times as well as bandwidth.
|
||||
Before pushing the script files onto your production server it is recommended to minify them to save on load times as well as bandwidth.
|
||||
|
||||
<br>
|
||||
|
||||
@ -15,20 +12,19 @@ load times as well as bandwidth.
|
||||
|
||||
## Steps
|
||||
|
||||
1. Open a terminal in `/data/minify` .
|
||||
1. Open a terminal in the root of the project.
|
||||
|
||||
2. Install the dependencies with:
|
||||
|
||||
```sh
|
||||
npm install
|
||||
```
|
||||
```sh
|
||||
npm i
|
||||
```
|
||||
|
||||
3. Start the minification with:
|
||||
|
||||
```sh
|
||||
node index.js
|
||||
```
|
||||
|
||||
```sh
|
||||
node run minify
|
||||
```
|
||||
|
||||
<!----------------------------------------------------------------------------->
|
||||
|
||||
38
minify/minify.js
Normal file
38
minify/minify.js
Normal file
@ -0,0 +1,38 @@
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import minify from "@node-minify/core";
|
||||
import terser from "@node-minify/terser";
|
||||
import cleanCSS from "@node-minify/clean-css";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const rootPath = path.resolve(__dirname, "../");
|
||||
|
||||
async function doMinify() {
|
||||
await minify({
|
||||
compressor: terser,
|
||||
input: path.join(rootPath, "data/src/*.js"),
|
||||
output: path.join(rootPath, "data/emulator.min.js"),
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error(err);
|
||||
})
|
||||
.then(function () {
|
||||
console.log("Minified JS");
|
||||
});
|
||||
await minify({
|
||||
compressor: cleanCSS,
|
||||
input: path.join(rootPath, "data/emulator.css"),
|
||||
output: path.join(rootPath, "data/emulator.min.css"),
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error(err);
|
||||
})
|
||||
.then(function () {
|
||||
console.log("Minified CSS");
|
||||
});
|
||||
}
|
||||
|
||||
console.log("Minifying");
|
||||
await doMinify();
|
||||
console.log("Minifying Done!");
|
||||
37
package.json
37
package.json
@ -1,16 +1,25 @@
|
||||
{
|
||||
"name": "@emulatorjs/emulatorjs",
|
||||
"version": "4.2.1",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/EmulatorJS/EmulatorJS.git"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "EmulatorJS is a frontend for RetroArch in the web browser.",
|
||||
"scripts": {
|
||||
"start": "http-server"
|
||||
},
|
||||
"dependencies": {
|
||||
"http-server": "^14.1.1"
|
||||
}
|
||||
"name": "@emulatorjs/emulatorjs",
|
||||
"version": "4.2.1",
|
||||
"type": "module",
|
||||
"description": "EmulatorJS is a frontend for RetroArch in the web browser.",
|
||||
"homepage": "https://emulatorjs.org",
|
||||
"license": "GPL-3.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/EmulatorJS/EmulatorJS.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/EmulatorJS/EmulatorJS/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "http-server",
|
||||
"minify": "node minify/minify.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@node-minify/clean-css": "^9.0.1",
|
||||
"@node-minify/core": "^9.0.2",
|
||||
"@node-minify/terser": "^9.0.1",
|
||||
"http-server": "^14.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user