Docker build works
This commit is contained in:
parent
8b21ff6e68
commit
8ad6b201da
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,4 +4,5 @@ dist
|
|||||||
src/*.js
|
src/*.js
|
||||||
src/**/*.js
|
src/**/*.js
|
||||||
public/index.html
|
public/index.html
|
||||||
public/main.*.css
|
public/main.css
|
||||||
|
public/css
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
server {
|
server {
|
||||||
listen 4173;
|
listen 4173;
|
||||||
|
|
||||||
root /app;
|
root /app/public;
|
||||||
|
|
||||||
location /app {
|
location /app {
|
||||||
try_files $uri $uri/ =404;
|
try_files $uri $uri/ =404;
|
||||||
|
@ -41,4 +41,4 @@ EXPOSE 4173
|
|||||||
RUN chmod +x /app/docker-entrypoint.sh
|
RUN chmod +x /app/docker-entrypoint.sh
|
||||||
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
||||||
|
|
||||||
CMD ["npm", "run", "build"]
|
CMD ["sh", "-c", "npm run build && nginx -g 'daemon off;'"]
|
@ -1,21 +1,24 @@
|
|||||||
import CleanCSS from "clean-css";
|
import CleanCSS from "clean-css";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { sbReadFile, sbRename, sbWriteFile } from "./shared/files";
|
import { sbMakeFolder, sbReadFile, sbRemoveAllCSS, sbWriteFile } from "./shared/files";
|
||||||
|
|
||||||
const mainCSSFilename = `main.${new Date().getTime()}.css`;
|
const mainCSSFilename = `main.${new Date().getTime()}.css`;
|
||||||
|
|
||||||
const cssFileInPath = path.join(__dirname, "../", "./public", "main.css");
|
const cssFilePath = path.join(__dirname, "../public/css");
|
||||||
const cssFileOutPath = path.join(__dirname, "../", "./public", mainCSSFilename);
|
const cssFileInPath = path.join(__dirname, "../public", "main.css");
|
||||||
const indexFileInOutPath = path.join(__dirname, "../", "./public", "index.html");
|
const cssFileOutPath = path.join(cssFilePath, mainCSSFilename);
|
||||||
|
const indexFileInOutPath = path.join(__dirname, "../public", "index.html");
|
||||||
|
|
||||||
async function start(): Promise<void> {
|
async function start(): Promise<void> {
|
||||||
await sbRename(cssFileInPath, cssFileOutPath);
|
await sbRemoveAllCSS(cssFilePath);
|
||||||
const css = await sbReadFile(cssFileOutPath);
|
await sbMakeFolder(cssFilePath);
|
||||||
|
|
||||||
|
const css = await sbReadFile(cssFileInPath);
|
||||||
await sbWriteFile(cssFileOutPath, new CleanCSS().minify(css).styles);
|
await sbWriteFile(cssFileOutPath, new CleanCSS().minify(css).styles);
|
||||||
|
|
||||||
const index = await sbReadFile(indexFileInOutPath);
|
const index = await sbReadFile(indexFileInOutPath);
|
||||||
const cssLink = `<link rel="stylesheet" href="./main.css" crossorigin="">`;
|
const cssLink = `<link rel="stylesheet" href="./main.css" crossorigin="">`;
|
||||||
const cssLinkReplacement = `<link rel="stylesheet" href="./${mainCSSFilename}" crossorigin="" />`;
|
const cssLinkReplacement = `<link rel="stylesheet" href="./css/${mainCSSFilename}" crossorigin="" />`;
|
||||||
|
|
||||||
await sbWriteFile(indexFileInOutPath, index.replace(cssLink, cssLinkReplacement));
|
await sbWriteFile(indexFileInOutPath, index.replace(cssLink, cssLinkReplacement));
|
||||||
}
|
}
|
||||||
|
@ -36,3 +36,30 @@ export async function sbRename(fileNameOld: string, fileNameNew: string): Promis
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function sbMakeFolder(path: string): Promise<boolean> {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
try {
|
||||||
|
await fs.mkdir(path, { recursive: true });
|
||||||
|
return resolve(true);
|
||||||
|
} catch (exception) {
|
||||||
|
console.error(`Could not make folder: ${path}`, exception);
|
||||||
|
reject(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function sbRemoveAllCSS(path: string): Promise<boolean> {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
try {
|
||||||
|
await fs.rm(path, {
|
||||||
|
recursive: true,
|
||||||
|
force: true,
|
||||||
|
});
|
||||||
|
return resolve(true);
|
||||||
|
} catch (exception) {
|
||||||
|
console.error(`Could not remove all CSS from path: ${path}`);
|
||||||
|
reject(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user