mirror of
https://github.com/JosunLP/BrowserExtensionTemplate.git
synced 2025-06-21 10:01:08 +00:00
integrading new css build
This commit is contained in:
parent
b225218e94
commit
977ce6719f
5 changed files with 87 additions and 75 deletions
|
@ -17,8 +17,6 @@
|
|||
"@types/node": "^20.13.0",
|
||||
"@webcomponents/webcomponentsjs": "^2.8.0",
|
||||
"sass": "^1.77.4",
|
||||
"ts-loader": "^9.5.1",
|
||||
"typescript": "^5.4.5",
|
||||
"vite": "^5.2.12",
|
||||
"vite-tsconfig-paths": "^4.3.2"
|
||||
},
|
||||
|
|
|
@ -1,8 +1,25 @@
|
|||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
const appConfig = JSON.parse(fs.readFileSync('./app.config.json', 'utf8'));
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
const appConfig = JSON.parse(fs.readFileSync("./app.config.json", "utf8"));
|
||||
const DEPLOY_TARGET = "./dist/";
|
||||
|
||||
function findCssFileNames(source: string): string[] {
|
||||
let files: string[] = [];
|
||||
const dir = fs.readdirSync(source);
|
||||
dir.forEach(function (file: string) {
|
||||
const sourceFile = path.join(source, file);
|
||||
const stat = fs.lstatSync(sourceFile);
|
||||
if (stat.isDirectory()) {
|
||||
files = files.concat(findCssFileNames(sourceFile));
|
||||
} else {
|
||||
if (path.extname(sourceFile) == ".css") {
|
||||
files.push(file);
|
||||
}
|
||||
}
|
||||
});
|
||||
return files;
|
||||
}
|
||||
|
||||
function findHtmlFilesRecursive(source: string): string[] {
|
||||
let files: string[] = [];
|
||||
const dir = fs.readdirSync(source);
|
||||
|
@ -12,7 +29,7 @@ function findHtmlFilesRecursive(source: string): string[] {
|
|||
if (stat.isDirectory()) {
|
||||
files = files.concat(findHtmlFilesRecursive(sourceFile));
|
||||
} else {
|
||||
if (path.extname(sourceFile) == '.html') {
|
||||
if (path.extname(sourceFile) == ".html") {
|
||||
files.push(sourceFile);
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +38,9 @@ function findHtmlFilesRecursive(source: string): string[] {
|
|||
}
|
||||
|
||||
function replaceKeywordsInHtmlFile(file: string) {
|
||||
let content = fs.readFileSync(file, 'utf8');
|
||||
const pairs: { key: string, value: string }[] = appConfig.htmlTemplatePairs;
|
||||
pairs.forEach(function (pair: { key: string, value: string }) {
|
||||
let content = fs.readFileSync(file, "utf8");
|
||||
const pairs: { key: string; value: string }[] = appConfig.htmlTemplatePairs;
|
||||
pairs.forEach(function (pair: { key: string; value: string }) {
|
||||
//@ts-ignore
|
||||
content = content.replaceAll(pair.key, pair.value);
|
||||
});
|
||||
|
@ -38,6 +55,18 @@ function buildHtmlFiles(source: string) {
|
|||
});
|
||||
}
|
||||
|
||||
findCssFileNames(DEPLOY_TARGET).forEach((file: string) => {
|
||||
const files = findHtmlFilesRecursive(DEPLOY_TARGET);
|
||||
files.forEach(function (htmlFile: string) {
|
||||
let content = fs.readFileSync(htmlFile, "utf8");
|
||||
content = content.replace(
|
||||
"</head>",
|
||||
`<link rel="stylesheet" href="./assets/${file}">\n</head>`
|
||||
);
|
||||
fs.writeFileSync(htmlFile, content);
|
||||
});
|
||||
});
|
||||
|
||||
buildHtmlFiles(DEPLOY_TARGET);
|
||||
|
||||
console.log("Parsed Files: ", findHtmlFilesRecursive(DEPLOY_TARGET));
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */,
|
||||
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
"lib": ["ESNext"], /* Specify library files to be included in the compilation. */
|
||||
"lib": ["ESNext", "DOM"], /* 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'. */
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
import { defineConfig } from 'vite';
|
||||
import { resolve } from 'path';
|
||||
import tsconfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
app: resolve(__dirname, 'src/app.ts'),
|
||||
settings: resolve(__dirname, 'src/settings.ts'),
|
||||
background: resolve(__dirname, 'src/background.ts'),
|
||||
},
|
||||
output: {
|
||||
entryFileNames: '[name].js',
|
||||
dir: resolve(__dirname, 'dist'),
|
||||
},
|
||||
},
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [
|
||||
tsconfigPaths(),
|
||||
],
|
||||
resolve: {
|
||||
extensions: ['.tsx', '.ts', '.scss', '.sass'],
|
||||
},
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
sass: {
|
||||
additionalData: `@import "@/src/sass/app.sass"`, // optional
|
||||
},
|
||||
},
|
||||
},
|
||||
esbuild: {
|
||||
include: /.*\.tsx?$/,
|
||||
exclude: [
|
||||
/node_modules/,
|
||||
/dist/,
|
||||
// /src\/background\.ts/,
|
||||
// /src\/settings\.ts/,
|
||||
// /src\/app\.ts/,
|
||||
],
|
||||
},
|
||||
});
|
28
vite.config.ts
Normal file
28
vite.config.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { defineConfig } from "vite";
|
||||
import { resolve } from "path";
|
||||
import tsconfigPaths from "vite-tsconfig-paths";
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
app: resolve(__dirname, "src/app.ts"),
|
||||
settings: resolve(__dirname, "src/settings.ts"),
|
||||
background: resolve(__dirname, "src/background.ts"),
|
||||
},
|
||||
output: {
|
||||
entryFileNames: "[name].js",
|
||||
dir: resolve(__dirname, "dist"),
|
||||
},
|
||||
},
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [tsconfigPaths()],
|
||||
resolve: {
|
||||
extensions: [".tsx", ".ts", ".scss", ".sass"],
|
||||
},
|
||||
esbuild: {
|
||||
include: /.*\.tsx?$/,
|
||||
exclude: [/node_modules/, /dist/],
|
||||
},
|
||||
});
|
Loading…
Add table
Reference in a new issue