Visit the Svelte tutorial to learn how to build Svelte apps.
8 |
9 |
10 |
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 JeffProd
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/esbuild.js:
--------------------------------------------------------------------------------
1 | const esbuild = require('esbuild')
2 | const liveServer = require("live-server") // dev server
3 | const sveltePlugin = require('esbuild-svelte') // esbuild plugin svelte
4 |
5 | function showUsage () {
6 | console.log('USAGE')
7 | console.log('node esbuild.js dev')
8 | console.log('node esbuild.js prod')
9 | process.exit(0)
10 | }
11 |
12 | if (process.argv.length < 3) {
13 | showUsage()
14 | }
15 |
16 | if (![ 'dev', 'prod' ].includes(process.argv[2])) {
17 | showUsage()
18 | }
19 |
20 | // production mode, or not
21 | const production = (process.argv[2] === 'prod')
22 |
23 | // esbuild watch in dev mode to rebuild out files
24 | let watch = false
25 | if (!production) {
26 | watch = {
27 | onRebuild(error) {
28 | if (error) console.error('esbuild: Watch build failed:', error.getMessage())
29 | else console.log('esbuild: Watch build succeeded')
30 | }
31 | }
32 | }
33 |
34 | // esbuild build options
35 | // see: https://esbuild.github.io/api/#build-api
36 | const options = {
37 | entryPoints: ['./src/main.js'],
38 | bundle: true,
39 | watch,
40 | format: 'iife',
41 | minify: production,
42 | sourcemap: false,
43 | outfile: './public/build/bundle.js', // and bundle.css
44 | plugins: [
45 | sveltePlugin()
46 | ]
47 | }
48 |
49 | // start web dev server
50 | if (!production) {
51 | const params = {
52 | port: 8080, // Set the server port. Defaults to 8080.
53 | root: "./public", // Set root directory that's being served. Defaults to cwd.
54 | open: false, // When false, it won't load your browser by default.
55 | wait: 1000, // Waits for all changes, before reloading. Defaults to 0 sec.
56 | logLevel: 2, // 0 = errors only, 1 = some, 2 = lots
57 | }
58 | liveServer.start(params)
59 | }
60 |
61 | // esbuild dev + prod
62 | esbuild.build(options).catch((err) => {
63 | console.error(err)
64 | process.exit(1)
65 | })
66 |
--------------------------------------------------------------------------------