major refactoring
- created a package.json - refactor with eslint - use modules - moved everything to webpack
This commit is contained in:
parent
b9a56f38f5
commit
09199ebec5
22
.eslintrc.yml
Normal file
22
.eslintrc.yml
Normal file
@ -0,0 +1,22 @@
|
||||
env:
|
||||
browser: true
|
||||
es2021: true
|
||||
node: true
|
||||
extends: eslint:recommended
|
||||
overrides: []
|
||||
parserOptions:
|
||||
ecmaVersion: latest
|
||||
sourceType: module
|
||||
rules:
|
||||
indent:
|
||||
- error
|
||||
- tab
|
||||
linebreak-style:
|
||||
- error
|
||||
- unix
|
||||
quotes:
|
||||
- error
|
||||
- double
|
||||
semi:
|
||||
- error
|
||||
- always
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
tags
|
||||
node_modules/
|
||||
dist/
|
9990
package-lock.json
generated
Normal file
9990
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
package.json
Normal file
47
package.json
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "encryptme",
|
||||
"version": "0.5.0",
|
||||
"description": "Simple online cryptography app.",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "webpack --config webpack.prod.js",
|
||||
"lint": "eslint --ext .js,.jsx src *.js",
|
||||
"start": "webpack serve --open --config webpack.dev.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/dogeystamp/encryptme.git"
|
||||
},
|
||||
"keywords": [
|
||||
"website",
|
||||
"cryptography",
|
||||
"encryption",
|
||||
"aes",
|
||||
"webapp",
|
||||
"aes-256",
|
||||
"aes-gcm",
|
||||
"decryption",
|
||||
"encryption-decryption",
|
||||
"cryptography-tools",
|
||||
"cryptography-utilities"
|
||||
],
|
||||
"author": "dogeystamp",
|
||||
"license": "BSD-2-Clause",
|
||||
"bugs": {
|
||||
"url": "https://github.com/dogeystamp/encryptme/issues"
|
||||
},
|
||||
"homepage": "https://github.com/dogeystamp/encryptme#readme",
|
||||
"devDependencies": {
|
||||
"css-loader": "^6.7.3",
|
||||
"css-minimizer-webpack-plugin": "^4.2.2",
|
||||
"eslint": "^8.33.0",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"mini-css-extract-plugin": "^2.7.2",
|
||||
"style-loader": "^3.3.1",
|
||||
"webpack": "^5.75.0",
|
||||
"webpack-cli": "^5.0.1",
|
||||
"webpack-dev-server": "^4.11.1",
|
||||
"webpack-merge": "^5.8.0"
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
header = document.createElement("div");
|
||||
header.classList.add("page-header");
|
||||
|
||||
header.innerHTML = `
|
||||
<a href="index.html"><h1>encryptme</h1></a>
|
||||
`
|
||||
|
||||
document.body.appendChild(header);
|
@ -12,6 +12,13 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
|
||||
*/
|
||||
|
||||
import { generateHeader } from "./templates.js";
|
||||
import "./style.css";
|
||||
generateHeader();
|
||||
|
||||
import { TabList } from "./interface.js";
|
||||
import { bufToB64, b64ToBuf } from "./util.js";
|
||||
|
||||
let tabs = new TabList({});
|
||||
|
||||
let encForm = tabs.createForm({label: "Encryption"});
|
||||
@ -23,7 +30,7 @@ let encMsg = encForm.createTextArea({
|
||||
let encPass = encForm.createPasswordInput({
|
||||
label: "Password",
|
||||
placeholder: "Enter your password",
|
||||
enabledFunc: function() {return !encManualKey.value}
|
||||
enabledFunc: function() {return !encManualKey.value;}
|
||||
});
|
||||
let encPbkdf2Iters = encForm.createNumberInput({
|
||||
label: "PBKDF2 iterations",
|
||||
@ -31,14 +38,14 @@ let encPbkdf2Iters = encForm.createNumberInput({
|
||||
step: 1,
|
||||
value: 300000,
|
||||
advanced: true,
|
||||
enabledFunc: function() {return !encManualKey.value}
|
||||
enabledFunc: function() {return !encManualKey.value;}
|
||||
});
|
||||
let encSalt = encForm.createMediumTextBox({
|
||||
label: "PBKDF2 salt",
|
||||
dataType: "b64",
|
||||
advanced: true,
|
||||
enabled: false,
|
||||
enabledFunc: function() {return encManualSalt.value && !encManualKey.value}
|
||||
enabledFunc: function() {return encManualSalt.value && !encManualKey.value;}
|
||||
});
|
||||
let encManualSalt = encForm.createCheckBox({
|
||||
label: "Use fixed salt instead of random",
|
||||
@ -63,7 +70,7 @@ let encKey = encForm.createMediumTextBox({
|
||||
dataType: "b64",
|
||||
advanced: true,
|
||||
enabled: false,
|
||||
enabledFunc: function() {return encManualKey.value}
|
||||
enabledFunc: function() {return encManualKey.value;}
|
||||
});
|
||||
let encManualKey = encForm.createCheckBox({
|
||||
label: "Use fixed key instead of password",
|
||||
@ -73,25 +80,25 @@ let encIV = encForm.createMediumTextBox({
|
||||
label: "IV",
|
||||
dataType: "b64",
|
||||
advanced: true,
|
||||
enabledFunc: function() {return encManualIV.value},
|
||||
visibleFunc: function() {return ["AES-GCM", "AES-CBC"].includes(encMode.value)}
|
||||
enabledFunc: function() {return encManualIV.value;},
|
||||
visibleFunc: function() {return ["AES-GCM", "AES-CBC"].includes(encMode.value);}
|
||||
});
|
||||
let encManualIV = encForm.createCheckBox({
|
||||
label: "Use fixed IV instead of random",
|
||||
advanced: true,
|
||||
visibleFunc: function() {return ["AES-GCM", "AES-CBC"].includes(encMode.value)}
|
||||
visibleFunc: function() {return ["AES-GCM", "AES-CBC"].includes(encMode.value);}
|
||||
});
|
||||
let encCounter = encForm.createMediumTextBox({
|
||||
label: "Counter",
|
||||
dataType: "b64",
|
||||
advanced: true,
|
||||
enabledFunc: function() {return encManualCounter.value},
|
||||
visibleFunc: function() {return encMode.value === "AES-CTR"}
|
||||
enabledFunc: function() {return encManualCounter.value;},
|
||||
visibleFunc: function() {return encMode.value === "AES-CTR";}
|
||||
});
|
||||
let encManualCounter = encForm.createCheckBox({
|
||||
label: "Use fixed counter instead of random",
|
||||
advanced: true,
|
||||
visibleFunc: function() {return encMode.value === "AES-CTR"}
|
||||
visibleFunc: function() {return encMode.value === "AES-CTR";}
|
||||
});
|
||||
let encMode = encForm.createDropDown({
|
||||
label: "AES mode",
|
||||
@ -132,14 +139,14 @@ let decMsg = decForm.createTextArea({
|
||||
let decPass = decForm.createPasswordInput({
|
||||
label: "Password",
|
||||
placeholder: "Enter your password",
|
||||
enabledFunc: function() {return !decManualKey.value}
|
||||
enabledFunc: function() {return !decManualKey.value;}
|
||||
});
|
||||
let decKey = decForm.createMediumTextBox({
|
||||
label: "Key",
|
||||
dataType: "b64",
|
||||
advanced: true,
|
||||
enabled: false,
|
||||
enabledFunc: function() {return decManualKey.value}
|
||||
enabledFunc: function() {return decManualKey.value;}
|
||||
});
|
||||
let decManualKey = decForm.createCheckBox({
|
||||
label: "Use fixed key instead of password",
|
||||
@ -265,19 +272,18 @@ encButton.handle.addEventListener("click", async function() {
|
||||
|
||||
let ciphertext;
|
||||
switch (encMode.value) {
|
||||
case "AES-GCM":
|
||||
ciphertext = await aesGcmEnc(key, iv, msgEncoded);
|
||||
break;
|
||||
case "AES-CBC":
|
||||
ciphertext = await aesCbcEnc(key, iv, msgEncoded);
|
||||
break;
|
||||
case "AES-CTR":
|
||||
ciphertext = await aesCtrEnc(key, counter, msgEncoded);
|
||||
break;
|
||||
default:
|
||||
let e = Error(`Mode '${encMode.value}' is not implemented.`);
|
||||
encMode.handleError(e);
|
||||
return;
|
||||
case "AES-GCM":
|
||||
ciphertext = await aesGcmEnc(key, iv, msgEncoded);
|
||||
break;
|
||||
case "AES-CBC":
|
||||
ciphertext = await aesCbcEnc(key, iv, msgEncoded);
|
||||
break;
|
||||
case "AES-CTR":
|
||||
ciphertext = await aesCtrEnc(key, counter, msgEncoded);
|
||||
break;
|
||||
default:
|
||||
encMode.handleError(Error(`Mode '${encMode.value}' is not implemented.`));
|
||||
return;
|
||||
}
|
||||
|
||||
encOutRaw.value = ciphertext;
|
||||
@ -290,7 +296,7 @@ encButton.handle.addEventListener("click", async function() {
|
||||
"encMode": encMode.value,
|
||||
"encKeySize": encKeySize.value,
|
||||
"pbkdf2Iters": pbkdf2Iters,
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
async function aesGcmDec(key, iv, ciphertext) {
|
||||
@ -380,18 +386,18 @@ decButton.handle.addEventListener("click", async function() {
|
||||
|
||||
try {
|
||||
switch (encMode) {
|
||||
case "AES-GCM":
|
||||
plaintext = await aesGcmDec(key, iv, ciphertext);
|
||||
break;
|
||||
case "AES-CBC":
|
||||
plaintext = await aesCbcDec(key, iv, ciphertext);
|
||||
break;
|
||||
case "AES-CTR":
|
||||
plaintext = await aesCtrDec(key, counter, ciphertext);
|
||||
break;
|
||||
default:
|
||||
throw Error(`Mode '${encMode.value}' is not implemented.`);
|
||||
}
|
||||
case "AES-GCM":
|
||||
plaintext = await aesGcmDec(key, iv, ciphertext);
|
||||
break;
|
||||
case "AES-CBC":
|
||||
plaintext = await aesCbcDec(key, iv, ciphertext);
|
||||
break;
|
||||
case "AES-CTR":
|
||||
plaintext = await aesCtrDec(key, counter, ciphertext);
|
||||
break;
|
||||
default:
|
||||
throw Error(`Mode '${encMode.value}' is not implemented.`);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.message !== "" && e.message !== undefined) {
|
||||
decMsg.handleError(e, "Error during decryption.");
|
3
src/index.js
Normal file
3
src/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
import { generateHeader } from "./templates.js";
|
||||
import "./style.css";
|
||||
generateHeader();
|
@ -12,6 +12,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
|
||||
*/
|
||||
|
||||
import { b64ToBuf, bufToB64 } from "./util.js";
|
||||
|
||||
class InterfaceElement {
|
||||
rootNodes = [];
|
||||
|
||||
@ -105,7 +107,7 @@ class Form extends InterfaceElement {
|
||||
}
|
||||
|
||||
let advancedToggle = this.createCheckBox({label: "Advanced settings"});
|
||||
advancedToggle.handle.addEventListener('change', function() {
|
||||
advancedToggle.handle.addEventListener("change", function() {
|
||||
this.advanced = advancedToggle.value;
|
||||
}.bind(this));
|
||||
|
||||
@ -179,7 +181,7 @@ class Form extends InterfaceElement {
|
||||
|
||||
createMediumTextBox(params) {
|
||||
params.tag = document.createElement("textarea");
|
||||
params.tag.classList.add("mediumbox")
|
||||
params.tag.classList.add("mediumbox");
|
||||
dataTypeSupports(params, ["plaintext", "b64", "json-b64"]);
|
||||
return this.createElem(params);
|
||||
}
|
||||
@ -281,30 +283,11 @@ class Form extends InterfaceElement {
|
||||
}
|
||||
}
|
||||
|
||||
function b64ToBuf (b64) {
|
||||
let ascii = atob(b64);
|
||||
let buf = new ArrayBuffer(ascii.length);
|
||||
let bytes = new Uint8Array(buf);
|
||||
for (var i = 0; i < ascii.length; i++) {
|
||||
bytes[i] = ascii.charCodeAt(i);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
function bufToB64 (buf) {
|
||||
let bytes = new Uint8Array(buf);
|
||||
let ascii = '';
|
||||
for (var i = 0; i < bytes.byteLength; i++) {
|
||||
ascii += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return btoa(ascii);
|
||||
}
|
||||
|
||||
class FormElement extends InterfaceElement {
|
||||
constructor({tag, fragment, advanced=false, form,
|
||||
value, dataType, placeholder,
|
||||
labelTag, label="",
|
||||
enabled=true, enabledFunc,
|
||||
enabledFunc,
|
||||
visibleFunc
|
||||
}) {
|
||||
let oriVisibleFunc = visibleFunc;
|
||||
@ -315,7 +298,7 @@ class FormElement extends InterfaceElement {
|
||||
visibleFunc: function() {
|
||||
let res;
|
||||
if (oriVisibleFunc) {
|
||||
res = oriVisibleFunc()
|
||||
res = oriVisibleFunc();
|
||||
} else {
|
||||
res = true;
|
||||
}
|
||||
@ -355,61 +338,62 @@ class FormElement extends InterfaceElement {
|
||||
get value() {
|
||||
this.clearAlerts();
|
||||
switch (this.dataType) {
|
||||
case "number":
|
||||
if (this.handle.checkValidity() == false) {
|
||||
this.alertBox("alert-error", this.handle.validationMessage);
|
||||
return undefined;
|
||||
}
|
||||
return Number(this.handle.value);
|
||||
case "plaintext":
|
||||
return this.handle.value;
|
||||
case "b64":
|
||||
try {
|
||||
return b64ToBuf(this.handle.value);
|
||||
} catch (e) {
|
||||
this.alertBox("alert-error", "Invalid base64 value.");
|
||||
return;
|
||||
}
|
||||
case "json-b64":
|
||||
let jsonString;
|
||||
try {
|
||||
jsonString = atob(this.handle.value);
|
||||
} catch (e) {
|
||||
this.alertBox("alert-error", "Invalid base64 value.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(jsonString);
|
||||
} catch (e) {
|
||||
this.alertBox("alert-error", "Invalid JSON encoding.");
|
||||
return;
|
||||
}
|
||||
case "bool":
|
||||
return this.handle.checked;
|
||||
case "category":
|
||||
return this.handle.value;
|
||||
case "none":
|
||||
case "number":
|
||||
if (this.handle.checkValidity() == false) {
|
||||
this.alertBox("alert-error", this.handle.validationMessage);
|
||||
return undefined;
|
||||
}
|
||||
return Number(this.handle.value);
|
||||
case "plaintext":
|
||||
return this.handle.value;
|
||||
case "b64":
|
||||
try {
|
||||
return b64ToBuf(this.handle.value);
|
||||
} catch (e) {
|
||||
this.handleError(Error("Invalid base64 value."));
|
||||
return undefined;
|
||||
}
|
||||
case "json-b64": {
|
||||
let jsonString;
|
||||
try {
|
||||
jsonString = atob(this.handle.value);
|
||||
} catch (e) {
|
||||
this.handleError(Error("Invalid base64 value."));
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(jsonString);
|
||||
} catch (e) {
|
||||
this.handleError(Error("Invalid JSON encoding."));
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
case "bool":
|
||||
return this.handle.checked;
|
||||
case "category":
|
||||
return this.handle.value;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
set value(x) {
|
||||
switch (this.dataType) {
|
||||
case "number":
|
||||
case "plaintext":
|
||||
this.handle.value = x;
|
||||
break;
|
||||
case "b64":
|
||||
this.handle.value = bufToB64(x);
|
||||
break;
|
||||
case "json-b64":
|
||||
this.handle.value = btoa(JSON.stringify(x));
|
||||
break;
|
||||
case "bool":
|
||||
this.handle.checked = x;
|
||||
break;
|
||||
case "category":
|
||||
this.handle.value = x;
|
||||
break;
|
||||
case "number":
|
||||
case "plaintext":
|
||||
this.handle.value = x;
|
||||
break;
|
||||
case "b64":
|
||||
this.handle.value = bufToB64(x);
|
||||
break;
|
||||
case "json-b64":
|
||||
this.handle.value = btoa(JSON.stringify(x));
|
||||
break;
|
||||
case "bool":
|
||||
this.handle.checked = x;
|
||||
break;
|
||||
case "category":
|
||||
this.handle.value = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,24 +402,24 @@ class FormElement extends InterfaceElement {
|
||||
// type is alert-error or alert-info
|
||||
|
||||
if (this.handle === undefined) {
|
||||
throw `can not add alert: still undefined`;
|
||||
throw "can not add alert: still undefined";
|
||||
}
|
||||
|
||||
if (this.hidden === true) {
|
||||
throw `can not add alert: hidden`;
|
||||
throw "can not add alert: hidden";
|
||||
}
|
||||
|
||||
if (title === undefined) {
|
||||
switch (type) {
|
||||
case "alert-info":
|
||||
title = "Info: ";
|
||||
break;
|
||||
case "alert-error":
|
||||
title = "Error: ";
|
||||
break;
|
||||
default:
|
||||
title = "";
|
||||
break;
|
||||
case "alert-info":
|
||||
title = "Info: ";
|
||||
break;
|
||||
case "alert-error":
|
||||
title = "Error: ";
|
||||
break;
|
||||
default:
|
||||
title = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,7 +467,7 @@ class Tab extends InterfaceElement {
|
||||
|
||||
class TabList extends InterfaceElement {
|
||||
constructor({tag, par=document.body}) {
|
||||
super({})
|
||||
super({});
|
||||
|
||||
this.par = par;
|
||||
|
||||
@ -497,7 +481,7 @@ class TabList extends InterfaceElement {
|
||||
par.appendChild(this.fragment);
|
||||
}
|
||||
|
||||
tabs = []
|
||||
tabs = [];
|
||||
|
||||
#activeForm;
|
||||
set activeForm(x) {
|
||||
@ -527,7 +511,7 @@ class TabList extends InterfaceElement {
|
||||
});
|
||||
this.tabs.push(tab);
|
||||
|
||||
tab.handle.addEventListener('click', function() {
|
||||
tab.handle.addEventListener("click", function() {
|
||||
this.activeForm = form;
|
||||
}.bind(this));
|
||||
|
||||
@ -539,3 +523,5 @@ class TabList extends InterfaceElement {
|
||||
return form;
|
||||
}
|
||||
}
|
||||
|
||||
export { TabList, FormElement, Form };
|
@ -3,15 +3,11 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>encryptme: Simple AES encryption/decryption</title>
|
||||
<meta name="description" content="Easy to use and simple online tool for AES encryption and decryption.
|
||||
Advanced settings allow control over the IV, AES mode, and PBKDF2 parameters.">
|
||||
</head>
|
||||
<body>
|
||||
<script src="scripts/header-template.js"></script>
|
||||
<h1>AES</h1>
|
||||
<script src="scripts/interface.js"></script>
|
||||
<script src="scripts/aes.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -3,12 +3,10 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>encryptme</title>
|
||||
<meta name="description" content="Easy to use and simple online tools for encryption and decryption.">
|
||||
</head>
|
||||
<body>
|
||||
<script src="scripts/header-template.js"></script>
|
||||
<h2>Tools</h2>
|
||||
<h3>Encryption/decryption</h3>
|
||||
<a href="aes.html">AES</a>
|
11
src/templates.js
Normal file
11
src/templates.js
Normal file
@ -0,0 +1,11 @@
|
||||
function generateHeader() {
|
||||
let header = document.createElement("div");
|
||||
header.classList.add("page-header");
|
||||
|
||||
header.innerHTML = `
|
||||
<a href="index.html"><h1>encryptme</h1></a>
|
||||
`;
|
||||
document.body.prepend(header);
|
||||
}
|
||||
|
||||
export { generateHeader };
|
34
src/util.js
Normal file
34
src/util.js
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
|
||||
Copyright 2023 dogeystamp <dogeystamp@disroot.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
function b64ToBuf (b64) {
|
||||
let ascii = atob(b64);
|
||||
let buf = new ArrayBuffer(ascii.length);
|
||||
let bytes = new Uint8Array(buf);
|
||||
for (var i = 0; i < ascii.length; i++) {
|
||||
bytes[i] = ascii.charCodeAt(i);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
function bufToB64 (buf) {
|
||||
let bytes = new Uint8Array(buf);
|
||||
let ascii = "";
|
||||
for (var i = 0; i < bytes.byteLength; i++) {
|
||||
ascii += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return btoa(ascii);
|
||||
}
|
||||
|
||||
export { b64ToBuf, bufToB64 };
|
46
webpack.common.js
Normal file
46
webpack.common.js
Normal file
@ -0,0 +1,46 @@
|
||||
const path = require("path");
|
||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
||||
|
||||
const pages = ["index", "aes"];
|
||||
|
||||
module.exports = {
|
||||
entry: pages.reduce((config, page) => {
|
||||
config[page] = `./src/${page}.js`;
|
||||
return config;
|
||||
}, {}),
|
||||
output: {
|
||||
filename: "[name].js",
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
clean: true,
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: {
|
||||
chunks: "all",
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new MiniCssExtractPlugin({
|
||||
filename: "[contenthash].css",
|
||||
chunkFilename: "[id].[contenthash].css",
|
||||
}),
|
||||
].concat(
|
||||
pages.map(
|
||||
(page) =>
|
||||
new HtmlWebpackPlugin({
|
||||
inject: true,
|
||||
template: `./src/pages/${page}.html`,
|
||||
filename: `${page}.html`,
|
||||
chunks: [page],
|
||||
})
|
||||
)
|
||||
),
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/i,
|
||||
use: [MiniCssExtractPlugin.loader, "css-loader"],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
10
webpack.dev.js
Normal file
10
webpack.dev.js
Normal file
@ -0,0 +1,10 @@
|
||||
const { merge } = require("webpack-merge");
|
||||
const common = require("./webpack.common.js");
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: "development",
|
||||
devtool: "inline-source-map",
|
||||
devServer: {
|
||||
static: "./dist",
|
||||
},
|
||||
});
|
13
webpack.prod.js
Normal file
13
webpack.prod.js
Normal file
@ -0,0 +1,13 @@
|
||||
const { merge } = require("webpack-merge");
|
||||
const common = require("./webpack.common.js");
|
||||
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: "production",
|
||||
optimization: {
|
||||
minimizer: [
|
||||
"...",
|
||||
new CssMinimizerPlugin(),
|
||||
]
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user