mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-02-17 00:49:47 +03:00
build tools: webpack with typescript and scss compilation
This commit is contained in:
parent
6069962d3e
commit
6184fe7efe
12 changed files with 1008 additions and 3357 deletions
2
.github/workflows/linux.yml
vendored
2
.github/workflows/linux.yml
vendored
|
@ -51,8 +51,6 @@ jobs:
|
|||
|
||||
- run: yarn install
|
||||
|
||||
- run: yarn tsc
|
||||
|
||||
- run: yarn build
|
||||
|
||||
- name: Install ${{ matrix.version }}
|
||||
|
|
2
Makefile
2
Makefile
|
@ -13,7 +13,7 @@ docs:
|
|||
cargo doc --no-deps --workspace --all-features
|
||||
|
||||
frontend-dev:
|
||||
yarn start
|
||||
yarn build
|
||||
|
||||
frontend:
|
||||
yarn build
|
||||
|
|
45
package.json
45
package.json
|
@ -1,38 +1,21 @@
|
|||
{
|
||||
"name": "frontend",
|
||||
"version": "0.1.0",
|
||||
"description": "mCaptcha/guard frontend",
|
||||
"name": "vanilla",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/mCaptcha/guard",
|
||||
"author": "Aravinth Manivannan <realaravinth@batsense.net>",
|
||||
"license": "AGPLv3 or above",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"start": "tsc templates/index.ts && webpack --config webpack.dev.js",
|
||||
"tsc": "tsc templates/index.ts",
|
||||
"build": "tsc templates/index.ts && webpack --config webpack.prod.js"
|
||||
"build": "webpack --mode production",
|
||||
"start": "webpack-dev-server --mode development --progress --color"
|
||||
},
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"css-loader": "^2.1.0",
|
||||
"file-loader": "^3.0.1",
|
||||
"html-loader": "^0.5.5",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
"mini-css-extract-plugin": "^0.5.0",
|
||||
"node-sass": "^4.11.0",
|
||||
"optimize-css-assets-webpack-plugin": "^5.0.1",
|
||||
"sass-loader": "^7.1.0",
|
||||
"style-loader": "^0.23.1",
|
||||
"ts-loader": "^9.1.1",
|
||||
"typescript": "^4.2.4",
|
||||
"webpack": "^4.29.6",
|
||||
"webpack-cli": "^3.2.3",
|
||||
"webpack-dev-server": "^3.2.1",
|
||||
"webpack-merge": "^4.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.0.0",
|
||||
"babel-loader": "^8.2.2",
|
||||
"clean-webpack-plugin": "^2.0.0",
|
||||
"loader-utils": "^2.0.0"
|
||||
"css-loader": "^5.2.4",
|
||||
"css-minimizer-webpack-plugin": "^2.0.0",
|
||||
"dart-sass": "^1.25.0",
|
||||
"mini-css-extract-plugin": "^1.6.0",
|
||||
"sass-loader": "^11.0.1",
|
||||
"ts-loader": "^8.0.0",
|
||||
"typescript": "^4.1.0",
|
||||
"webpack": "^5.0.0",
|
||||
"webpack-cli": "^4.6.0",
|
||||
"webpack-dev-server": "^3.1.14"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ lazy_static! {
|
|||
pub static ref SETTINGS: Settings = Settings::new().unwrap();
|
||||
pub static ref S: String = env::var("S").unwrap();
|
||||
pub static ref FILES: FileMap = FileMap::new();
|
||||
pub static ref JS: &'static str = FILES.get("./static-assets/bundle/main.js").unwrap();
|
||||
pub static ref JS: &'static str = FILES.get("./static-assets/bundle/bundle.js").unwrap();
|
||||
pub static ref CSS: &'static str = FILES.get("./static-assets/bundle/main.css").unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,3 @@ router.register(VIEWS.loginUser, login.index);
|
|||
router.register(VIEWS.addSiteKey, addSiteKey.index);
|
||||
|
||||
router.route();
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Removes trailing slashed from URI */
|
||||
const normalizeUri = (uri: string) => {
|
||||
if (!uri) {
|
||||
throw new Error('uri is empty');
|
||||
|
@ -31,17 +32,28 @@ const normalizeUri = (uri: string) => {
|
|||
return uri;
|
||||
};
|
||||
|
||||
/** URI<-> Fn mapping type */
|
||||
type routeTuple = {
|
||||
uri: string;
|
||||
fn: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Router that selectively executes fucntions
|
||||
* based on window.location.pathname
|
||||
* */
|
||||
export class Router {
|
||||
routes: Array<routeTuple>;
|
||||
constructor() {
|
||||
this.routes = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* registers a route-function pair with Router
|
||||
* @param {string} uri - route to be registered
|
||||
* @param {function} fn: - function to be registered when window.locatin.path
|
||||
* matches uri
|
||||
* */
|
||||
register(uri: string, fn: () => void) {
|
||||
// typechecks
|
||||
if (!uri) {
|
||||
|
@ -73,12 +85,15 @@ export class Router {
|
|||
this.routes.push(route);
|
||||
}
|
||||
|
||||
/**
|
||||
* executes registered function with route
|
||||
* matches window.pathname.location
|
||||
* */
|
||||
route() {
|
||||
this.routes.forEach(route => {
|
||||
// normalize for trailing slash
|
||||
let pattern = new RegExp(`^${route.uri}$`);
|
||||
let path = window.location.pathname;
|
||||
path = normalizeUri(path);
|
||||
const pattern = new RegExp(`^${route.uri}$`);
|
||||
const path = normalizeUri(window.location.pathname);
|
||||
if (path.match(pattern)) {
|
||||
//return route.fn.call();
|
||||
return route.fn();
|
||||
|
|
|
@ -1,71 +1,5 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
"allowJs": true /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
// "outDir": "./", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true /* Skip type checking of declaration files. */,
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
}
|
||||
"compilerOptions": {
|
||||
"sourceMap": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
module.exports = {
|
||||
entry: {
|
||||
main: './templates/index.js',
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.html$/,
|
||||
use: ['html-loader'],
|
||||
},
|
||||
{
|
||||
test: /\.(svg|png|jpg|gif)$/,
|
||||
use: {
|
||||
loader: 'file-loader',
|
||||
options: {
|
||||
name: '[name].[hash].[ext]',
|
||||
outputPath: 'imgs',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
48
webpack.config.js
Normal file
48
webpack.config.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
'use strict';
|
||||
const path = require('path');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
devtool: 'inline-source-map',
|
||||
mode: 'development',
|
||||
entry: './templates/index.ts',
|
||||
output: {
|
||||
filename: 'bundle.js',
|
||||
path: path.resolve(__dirname, './static-assets/bundle/'),
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
loader: 'ts-loader',
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.s[ac]ss$/i,
|
||||
use: [
|
||||
MiniCssExtractPlugin.loader,
|
||||
'css-loader',
|
||||
{
|
||||
loader: 'sass-loader',
|
||||
options: {
|
||||
implementation: require('dart-sass'),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts', '.tsx', '.js'],
|
||||
},
|
||||
|
||||
plugins: [new MiniCssExtractPlugin()],
|
||||
optimization: {
|
||||
minimizer: [
|
||||
// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
|
||||
`...`,
|
||||
new CssMinimizerPlugin(),
|
||||
],
|
||||
},
|
||||
};
|
|
@ -1,48 +0,0 @@
|
|||
const path = require('path');
|
||||
const common = require('./webpack.common');
|
||||
const merge = require('webpack-merge');
|
||||
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: 'development',
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
path: path.resolve(__dirname, 'static-assets/bundle'),
|
||||
},
|
||||
plugins: [
|
||||
new MiniCssExtractPlugin({filename: '[name].css'}),
|
||||
new CleanWebpackPlugin(),
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
MiniCssExtractPlugin.loader, //3. Extract css into files
|
||||
'css-loader', //2. Turns css into commonjs
|
||||
'sass-loader', //1. Turns sass into css
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
/*
|
||||
* plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
filename: 'register/index.html',
|
||||
template: path.resolve(__dirname, 'output/register/', 'index.html'),
|
||||
}),
|
||||
|
||||
new HtmlWebpackPlugin({
|
||||
filename: 'panel/index.html',
|
||||
template: path.resolve(__dirname, 'output/panel/', 'index.html'),
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
template: path.resolve(__dirname, 'output/', 'index.html'),
|
||||
}),
|
||||
],
|
||||
|
||||
*/
|
|
@ -1,68 +0,0 @@
|
|||
const path = require('path');
|
||||
const common = require('./webpack.common');
|
||||
const merge = require('webpack-merge');
|
||||
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: 'production',
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
path: path.resolve(__dirname, 'static-assets/bundle'),
|
||||
},
|
||||
optimization: {
|
||||
minimizer: [
|
||||
new OptimizeCssAssetsPlugin(),
|
||||
new TerserPlugin(),
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new MiniCssExtractPlugin({filename: '[name].css'}),
|
||||
new CleanWebpackPlugin(),
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
MiniCssExtractPlugin.loader, //3. Extract css into files
|
||||
'css-loader', //2. Turns css into commonjs
|
||||
'sass-loader', //1. Turns sass into css
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
/*
|
||||
* new HtmlWebpackPlugin({
|
||||
template: path.resolve(__dirname, 'output', 'index.html'),
|
||||
minify: {
|
||||
removeAttributeQuotes: true,
|
||||
collapseWhitespace: true,
|
||||
removeComments: true,
|
||||
},
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
filename: 'register/index.html', // output filename
|
||||
template: path.resolve(__dirname, 'output/register/', 'index.html'),
|
||||
minify: {
|
||||
removeAttributeQuotes: true,
|
||||
collapseWhitespace: true,
|
||||
removeComments: true,
|
||||
},
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
filename: 'panel/index.html',
|
||||
template: './output/panel/index.html',
|
||||
minify: {
|
||||
removeAttributeQuotes: true,
|
||||
collapseWhitespace: true,
|
||||
removeComments: true,
|
||||
}
|
||||
}),
|
||||
|
||||
*/
|
Loading…
Add table
Reference in a new issue