Add build and watch mode
This commit is contained in:
parent
c80e25f8b0
commit
58bc7b8d5f
26
ui/build.js
26
ui/build.js
|
@ -1,22 +1,25 @@
|
|||
const fs = require('fs')
|
||||
const esbuild = require('esbuild')
|
||||
const bs = require('browser-sync').create()
|
||||
const historyApiFallback = require('connect-history-api-fallback')
|
||||
|
||||
const production = process.env.NODE_ENV == 'production'
|
||||
const watchMode = process.argv[2] == 'watch'
|
||||
|
||||
let builderPromise = require('esbuild').build({
|
||||
const esbuildOptions = {
|
||||
entryPoints: ['src/index.js'],
|
||||
publicPath: '/',
|
||||
outdir: 'dist',
|
||||
// format: 'esm',
|
||||
format: 'esm',
|
||||
bundle: true,
|
||||
platform: 'browser',
|
||||
target: ['chrome58', 'firefox57', 'safari11', 'edge16'],
|
||||
// splitting: true,
|
||||
splitting: true,
|
||||
minify: production,
|
||||
sourcemap: !production,
|
||||
loader: {
|
||||
'.js': 'jsx',
|
||||
'.svg': 'text',
|
||||
'.svg': 'file',
|
||||
'.woff': 'file',
|
||||
'.woff2': 'file',
|
||||
'.ttf': 'file',
|
||||
|
@ -24,13 +27,21 @@ let builderPromise = require('esbuild').build({
|
|||
'.png': 'file',
|
||||
},
|
||||
define: {
|
||||
'process.env.PHOTOVIEW_API_ENDPOINT': '"http://localhost:4001/"',
|
||||
'process.env.NODE_ENV': '"development"',
|
||||
},
|
||||
incremental: true,
|
||||
})
|
||||
incremental: watchMode,
|
||||
}
|
||||
|
||||
fs.rmdirSync('dist/', {
|
||||
recursive: true,
|
||||
})
|
||||
fs.mkdirSync('dist/')
|
||||
fs.copyFileSync('src/index.html', 'dist/index.html')
|
||||
|
||||
if (watchMode) {
|
||||
let builderPromise = esbuild.build(esbuildOptions)
|
||||
|
||||
bs.init({
|
||||
server: {
|
||||
baseDir: './dist',
|
||||
|
@ -45,3 +56,6 @@ bs.watch('src/**/*.js').on('change', async args => {
|
|||
builderPromise = (await builderPromise).rebuild()
|
||||
bs.reload(args)
|
||||
})
|
||||
} else {
|
||||
esbuild.buildSync(esbuildOptions)
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
"url-join": "^4.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "parcel start src/index.html",
|
||||
"build": "parcel build src/index.html --no-source-maps",
|
||||
"start": "node build.js watch",
|
||||
"build": "NODE_ENV=production node build.js",
|
||||
"test": "npm run lint && npm run jest",
|
||||
"lint": "eslint ./src --max-warnings 0 --cache",
|
||||
"jest": "jest"
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="manifest" href="./manifest.webmanifest" />
|
||||
|
||||
<link rel="stylesheet" href="/src/index.css" />
|
||||
|
||||
<!-- Apple touch devices -->
|
||||
<link rel="apple-touch-icon" href="./assets/apple-touch-icon.png" />
|
||||
<meta name="apple-mobile-web-app-title" content="Photoview" />
|
||||
|
@ -13,6 +15,6 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script src="/index.js"></script>
|
||||
<script type="module" src="/src/index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue