Skip to content

Commit

Permalink
Merge pull request #1 from baurine/refine_builder
Browse files Browse the repository at this point in the history
refine builder
  • Loading branch information
awran5 authored Dec 3, 2021
2 parents 9396182 + a18bce8 commit 56f3c78
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
dist
24 changes: 17 additions & 7 deletions builder.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const { start } = require('live-server')
const { watch } = require('chokidar')
const { build } = require('esbuild')
const fs = require('fs-extra')

const isDev = process.env.NODE_ENV !== 'production'

/**
* Live Server Params
* @link https://www.npmjs.com/package/live-server#usage-from-node
*/
const serverParams = {
port: 8181, // Set the server port. Defaults to 8080.
root: 'public', // Set root directory that's being served. Defaults to cwd.
root: 'dist', // Set root directory that's being served. Defaults to cwd.
open: true // When false, it won't load your browser by default.
// host: "0.0.0.0", // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.
// ignore: 'scss,my/templates', // comma-separated string for paths to ignore
Expand All @@ -27,20 +30,27 @@ const buildParams = {
color: true,
entryPoints: ['src/index.tsx'],
loader: { '.ts': 'tsx' },
outdir: 'public',
minify: true,
outdir: 'dist',
minify: !isDev,
format: 'cjs',
bundle: true,
sourcemap: true,
logLevel: 'error',
incremental: true
}
;(async () => {
fs.removeSync('dist')
fs.copySync('public', 'dist')

const builder = await build(buildParams)

watch('src/**/*.{ts,tsx}').on('all', () => {
builder.rebuild()
})
if (isDev) {
watch('src/**/*', { ignoreInitial: true }).on('all', () => {
builder.rebuild()
})

start(serverParams)
start(serverParams)
} else {
process.exit(0)
}
})()
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"pre-commit": "lint-staged",
"lint": "eslint \"src/**/*.{ts,tsx}\" --max-warnings=0",
"start": "node builder.js",
"build": "esbuild src/index.tsx --minify --format=cjs --outdir=public --sourcemap --bundle"
"build": "NODE_ENV=production node builder.js"
},
"dependencies": {
"fs-extra": "^10.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
Expand Down
25 changes: 24 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,15 @@ from@~0:
resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe"
integrity sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=

fs-extra@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -1457,7 +1466,7 @@ globby@^11.0.3:
merge2 "^1.3.0"
slash "^3.0.0"

graceful-fs@^4.1.11, graceful-fs@^4.1.2:
graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.8"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==
Expand Down Expand Up @@ -1923,6 +1932,15 @@ json5@^1.0.1:
dependencies:
minimist "^1.2.0"

jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"

"jsx-ast-utils@^2.4.1 || ^3.0.0", jsx-ast-utils@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.2.0.tgz#41108d2cec408c3453c1bbe8a4aae9e1e2bd8f82"
Expand Down Expand Up @@ -3253,6 +3271,11 @@ union-value@^1.0.0:
is-extendable "^0.1.1"
set-value "^2.0.1"

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

unix-crypt-td-js@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/unix-crypt-td-js/-/unix-crypt-td-js-1.1.4.tgz#4912dfad1c8aeb7d20fa0a39e4c31918c1d5d5dd"
Expand Down

0 comments on commit 56f3c78

Please sign in to comment.