Minify
This commit is contained in:
parent
f6b89012e5
commit
6687d61966
2
DOCS.md
2
DOCS.md
@ -117,7 +117,7 @@ app.select("com.example");
|
|||||||
// Добавление
|
// Добавление
|
||||||
app.add(['<button>123</button>']);
|
app.add(['<button>123</button>']);
|
||||||
app.draw();
|
app.draw();
|
||||||
const map = app.map();
|
const map = app.map(); // Или app.component()
|
||||||
map.root // Доступ к элементу DOM
|
map.root // Доступ к элементу DOM
|
||||||
map.app(); // Исходный элемент Find
|
map.app(); // Исходный элемент Find
|
||||||
map.merge(); // Объединить HTML в элемент
|
map.merge(); // Объединить HTML в элемент
|
||||||
|
|||||||
25
Find/Find.js
25
Find/Find.js
@ -107,11 +107,7 @@ class FindObjectMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const tags = {
|
export default class Find {
|
||||||
"mobile" : `<meta name="viewport" content="width=device-width, initial-scale=1"></meta>`
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class {
|
|
||||||
|
|
||||||
/* Public section */
|
/* Public section */
|
||||||
|
|
||||||
@ -124,8 +120,8 @@ export default class {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
static tags(name) {
|
static createApp() {
|
||||||
return tags[name];
|
return Find;
|
||||||
}
|
}
|
||||||
|
|
||||||
static attach(x, f) {
|
static attach(x, f) {
|
||||||
@ -136,6 +132,14 @@ export default class {
|
|||||||
return `<link rel="stylesheet" href="${text.replace("\"", """)}"></link>`;
|
return `<link rel="stylesheet" href="${text.replace("\"", """)}"></link>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static js(text) {
|
||||||
|
return `<script src="${text.replace("\"", """)}"></script>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static content(text) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
static search(name) {
|
static search(name) {
|
||||||
return document.getElementById(name);
|
return document.getElementById(name);
|
||||||
}
|
}
|
||||||
@ -271,6 +275,10 @@ export default class {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
component() {
|
||||||
|
return this.map();
|
||||||
|
}
|
||||||
|
|
||||||
title(id_, html_) {
|
title(id_, html_) {
|
||||||
let id = undefined;
|
let id = undefined;
|
||||||
let html = undefined;
|
let html = undefined;
|
||||||
@ -373,6 +381,9 @@ export default class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
map() {
|
map() {
|
||||||
|
if (typeof this.__id === "undefined") {
|
||||||
|
PrivateFind.findTypeError(this.__id, "number или string")
|
||||||
|
}
|
||||||
return this._map;
|
return this._map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,4 +13,5 @@ cp -rv Find/* ~/Find_js
|
|||||||
cd ~/Find
|
cd ~/Find
|
||||||
php -S localhost:8000
|
php -S localhost:8000
|
||||||
# Откройте http://localhost:8000
|
# Откройте http://localhost:8000
|
||||||
|
# Эта страница позволит получить минифицированную версию Find.js
|
||||||
```
|
```
|
||||||
@ -32,8 +32,9 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="test"></div>
|
<div id="root"></div>
|
||||||
<script type="module" src="test.js"></script>
|
<script src="terser.min.js"></script>
|
||||||
|
<script type="module" src="index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
105
index.js
Normal file
105
index.js
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
import Find from './Find/Find.js';
|
||||||
|
|
||||||
|
const ROOT_OBJECT = 'root';
|
||||||
|
|
||||||
|
class MyApp extends Find.createApp() {
|
||||||
|
constructor(name) {
|
||||||
|
const root = Find.search(name);
|
||||||
|
super(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this.select('com.example');
|
||||||
|
this.setMeta();
|
||||||
|
this.setTitle();
|
||||||
|
this.setForms();
|
||||||
|
this.render();
|
||||||
|
this.attachEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
setMeta() {
|
||||||
|
this.meta([
|
||||||
|
Find.css('bulma.min.css'),
|
||||||
|
Find.content('<meta name="viewport" content="width=device-width, initial-scale=1">'),
|
||||||
|
Find.content(
|
||||||
|
`<style>
|
||||||
|
body {
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
</style>`
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTitle() {
|
||||||
|
this.title('Минификатор FInd.js на Find.js');
|
||||||
|
}
|
||||||
|
|
||||||
|
setForms() {
|
||||||
|
this.add([
|
||||||
|
Find.content(
|
||||||
|
`<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<p id="title" class="card-header-title">Минификация Find.js</p>
|
||||||
|
</div>
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="content">
|
||||||
|
<button
|
||||||
|
class="button"
|
||||||
|
id="minify"
|
||||||
|
style="width: 100%"
|
||||||
|
>Минифицировать</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
mwait(t) {
|
||||||
|
const root = app.component();
|
||||||
|
const title = root.id('title');
|
||||||
|
if (t === true) {
|
||||||
|
title.text('Минификация Find.js в процессе...');
|
||||||
|
} else {
|
||||||
|
if (typeof t === "string") {
|
||||||
|
title.text(t);
|
||||||
|
} else {
|
||||||
|
title.text('Минификация Find.js');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
attachEvents() {
|
||||||
|
const root = this.component();
|
||||||
|
const button = root.id('minify');
|
||||||
|
button.attach('click', (app) => {
|
||||||
|
this.mwait(true);
|
||||||
|
this.minifyFind();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async minifyFind() {
|
||||||
|
let response = await fetch('Find/Find.js');
|
||||||
|
if (response.ok) {
|
||||||
|
let code = await response.text();
|
||||||
|
let minif = await Terser.minify(code, { sourceMap: false });
|
||||||
|
this.uploadJS("find.min.js", minif.code);
|
||||||
|
this.mwait(false);
|
||||||
|
} else {
|
||||||
|
this.mwait("Ошибка HTTP: " + response.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadJS(filename, content) {
|
||||||
|
const blob = new Blob([content], { type: 'application/javascript' });
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = URL.createObjectURL(blob);
|
||||||
|
link.download = filename;
|
||||||
|
link.click();
|
||||||
|
URL.revokeObjectURL(link.href);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const app = new MyApp(ROOT_OBJECT);
|
||||||
|
app.init();
|
||||||
33787
terser.min.js
vendored
Normal file
33787
terser.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
33
test.js
33
test.js
@ -1,33 +0,0 @@
|
|||||||
import Find from "./Find/Find.js";
|
|
||||||
let app = new Find(Find.search("test")).select("com.example").title("Мой тест").meta([
|
|
||||||
Find.css("bulma.min.css"),
|
|
||||||
'<meta name="viewport" content="width=device-width, initial-scale=1">'
|
|
||||||
]).meta([
|
|
||||||
`<style>
|
|
||||||
body {
|
|
||||||
margin: 20px;
|
|
||||||
}
|
|
||||||
</style>`
|
|
||||||
]).add([(() => {
|
|
||||||
return `
|
|
||||||
<input class="input" type="text" placeholder="Логин..."></input><br>
|
|
||||||
<input
|
|
||||||
class="input"
|
|
||||||
style="margin-top: 10px;"
|
|
||||||
type="password" placeholder="Пароль...">
|
|
||||||
</input>
|
|
||||||
<br>
|
|
||||||
<button class="button" style="margin-top: 10px;">Войти</button>
|
|
||||||
<div id="user"></div>
|
|
||||||
`;
|
|
||||||
})()]).draw().map().id("user").html(
|
|
||||||
`<button
|
|
||||||
class="button"
|
|
||||||
id="reload"
|
|
||||||
style="margin-top: 10px;"
|
|
||||||
>Перезагрузить</button>`).id("reload").attach("click", () => {
|
|
||||||
location.reload();
|
|
||||||
}).main().merge().app().title(2).draw();
|
|
||||||
/*.title(2).draw();*/
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user