Skip to content

Commit

Permalink
build(esbuild): replace webpack with esbuil
Browse files Browse the repository at this point in the history
fix #27
  • Loading branch information
FreekMencke committed Dec 4, 2022
1 parent c0a9edb commit e9637b5
Show file tree
Hide file tree
Showing 13 changed files with 1,287 additions and 1,727 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ scripts
.dockerignore
.editorconfig
.gitignore
.travis.yml
Dockerfile
LICENSE
README.md
3 changes: 0 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
dist
node_modules
scripts
.vscode
.eslintrc.js
webpack.config.js
44 changes: 23 additions & 21 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
module.exports = {
root: true,
env: {
browser: true,
es6: true,
node: true,
},
parser: "@typescript-eslint/parser",
parser: '@typescript-eslint/parser',
parserOptions: {
project: "tsconfig.json",
sourceType: "module",
project: [
'tsconfig.json',
'tsconfig.eslint.json',
],
sourceType: 'module',
},
plugins: ["@typescript-eslint"],
plugins: ['@typescript-eslint'],
rules: {
"@typescript-eslint/indent": ["error", 2],
"@typescript-eslint/member-delimiter-style": [
"error",
'@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: "semi",
delimiter: 'semi',
requireLast: true,
},
singleline: {
delimiter: "semi",
delimiter: 'semi',
requireLast: false,
},
},
],
"@typescript-eslint/quotes": [
"error",
"single",
'@typescript-eslint/quotes': [
'error',
'single',
{
avoidEscape: true,
},
],
"@typescript-eslint/semi": ["error", "always"],
"comma-dangle": ["error", "always-multiline"],
"max-classes-per-file": "off",
"no-console": "error",
"no-multiple-empty-lines": ["error", { max: 1 }],
"no-redeclare": "error",
"no-return-await": "error",
"prefer-const": "error",
'@typescript-eslint/semi': ['error', 'always'],
'comma-dangle': ['error', 'always-multiline'],
'max-classes-per-file': 'off',
'no-console': 'error',
'no-multiple-empty-lines': ['error', { max: 1 }],
'no-redeclare': 'error',
'no-return-await': 'error',
'prefer-const': 'error',
},
};
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
dist
node_modules
.vscode

**/*.hidden.*
**/secrets/**
8 changes: 1 addition & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ WORKDIR /usr/src/app/
COPY . .
RUN npm ci
RUN npm run lint
RUN npm run build:ci

FROM node:18-alpine as prodDependencies
WORKDIR /usr/src/app/
COPY package.json package-lock.json ./
RUN npm ci --prod
RUN npm run build:prod

FROM node:18-alpine
WORKDIR /usr/app/
COPY --from=bundleBuilder /usr/src/app/dist/ ./
COPY --from=prodDependencies /usr/src/app/node_modules ./node_modules
EXPOSE 8080
HEALTHCHECK --interval=1m --timeout=2s \
CMD wget --quiet --tries=1 --spider http://localhost:8080/health || exit 1
Expand Down
39 changes: 39 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const argv = require('minimist')(process.argv.slice(2));
const esbuild = require('esbuild');

/** @type esbuild.BuildOptions */
const devConfig = {
sourcemap: 'linked',
};

/** @type esbuild.BuildOptions */
const prodConfig = {
minify: true,
};

/** @type esbuild.BuildOptions */
const config = {
entryPoints: ['src/main.ts'],
outfile: `dist/${process.env.npm_package_name}.js`,
bundle: true,
platform: 'node',
logLevel: 'info',

define: {
VERSION: 'process.env.npm_package_version',
DEVELOP: !!argv.dev,
},

watch: argv.watch,

metafile: argv.meta,
...(argv.dev ? devConfig : prodConfig),
};

if (argv.run) config.plugins = [require('@es-exec/esbuild-plugin-start').default({ script: `node dist/${process.env.npm_package_name}.js` })];

esbuild
.build(config)
.then(file => {
if (argv.meta) require('fs').writeFileSync('dist/meta.json', JSON.stringify(file.metafile));
});
Loading

0 comments on commit e9637b5

Please sign in to comment.