|
1 |
| -const compile = require( 'svelte/compiler' ).compile |
| 1 | +import { compile } from 'svelte/compiler'; |
| 2 | +import chokidar from 'chokidar'; |
| 3 | +import esbuild from 'esbuild'; |
| 4 | +import { readdirSync, statSync, existsSync, writeFileSync, readFileSync } from 'fs'; |
| 5 | +import { join, basename, resolve, dirname, relative } from 'path'; |
| 6 | +import { fileURLToPath } from 'url'; |
| 7 | +import sveltePlugin from 'esbuild-svelte'; |
| 8 | +import { sum } from 'lodash-es'; |
| 9 | +import { parse, serialize } from 'parse5'; |
| 10 | +import notifier from 'node-notifier'; |
| 11 | +import svelteConfig from './svelte.config.js'; |
| 12 | +import FiveServer from 'five-server'; |
2 | 13 |
|
3 |
| -const chokidar = require( 'chokidar' ); |
4 |
| -const esbuild = require( 'esbuild' ); |
5 |
| -const {readdirSync, statSync, existsSync, writeFileSync, readFileSync} = require( 'fs' ); |
6 |
| -const {join, basename, resolve, dirname, relative} = require( 'path' ); |
7 |
| -const sveltePlugin = require( 'esbuild-svelte' ); |
8 |
| -const {sum} = require( 'lodash' ); |
9 |
| -const parse5 = require( 'parse5' ); |
10 |
| -const notifier = require('node-notifier'); |
| 14 | +const __filename = fileURLToPath(import.meta.url); |
| 15 | +const __dirname = dirname(__filename); |
11 | 16 |
|
12 | 17 | process.on('uncaughtException', error => {
|
13 | 18 | notifier.notify({
|
@@ -57,12 +62,12 @@ function findPages( dir = '.', sink = [] ) {
|
57 | 62 | const _zId_prefix = `z_placeholder_${Math.floor( Math.random() * 1000000000 ).toString( 16 )}_`;
|
58 | 63 | const _zReplacer = s => debug_console_log( ['z-replace:', s, `"${_zId_prefix}${Buffer.from( s ).toString( 'base64' )}"`], 2 );
|
59 | 64 |
|
60 |
| -const zPlaceholderReplacer = content => |
61 |
| - |
| 65 | +const zPlaceholderReplacer = content => { |
62 | 66 | content?.replace( /\#\{\s*\w+\s*\}/gs, _zReplacer ) // #{ key }
|
63 | 67 | .replace( /\/\*\!\s*\w+\s*\*\//gs, _zReplacer ) // map /*! mapKey */
|
64 | 68 | .replace( /\[\s*\/\*\s*\w+\s*\*\/\s*\]/gs, _zReplacer ) // map [/* mapKey */]
|
65 | 69 | .replace( /\{\s*\/\*\s*\w+\s*\*\/\s*\}/gs, _zReplacer ); // map {/* mapKey */}
|
| 70 | +} |
66 | 71 |
|
67 | 72 | global.zPlaceholderReplacer = zPlaceholderReplacer;
|
68 | 73 |
|
@@ -101,7 +106,7 @@ function createBuilder( entryPoints ) {
|
101 | 106 | bundle: true,
|
102 | 107 | outdir: '.',
|
103 | 108 | write: false,
|
104 |
| - plugins: [svelteJsPathResolver, sveltePlugin( require( './svelte.config' ) )], |
| 109 | + plugins: [svelteJsPathResolver, sveltePlugin( svelteConfig ) ], |
105 | 110 | incremental: !!watch,
|
106 | 111 | sourcemap: false,
|
107 | 112 | minify,
|
@@ -129,7 +134,7 @@ function layoutFor( path, content = {} ) {
|
129 | 134 | const m = statSync( path ).mtimeMs;
|
130 | 135 | if( cache && m===cache.m ) return cache;
|
131 | 136 |
|
132 |
| - const tree = parse5.parse( |
| 137 | + const tree = parse( |
133 | 138 | path
|
134 | 139 | ? readFileSync( path, 'utf-8' )
|
135 | 140 | : `<!DOCTYPE html>
|
@@ -260,7 +265,7 @@ function layoutFor( path, content = {} ) {
|
260 | 265 | let html = content.html || '';
|
261 | 266 | const innerCss = (content.css || {}).code || '';
|
262 | 267 |
|
263 |
| - return parse5.serialize( tree ). |
| 268 | + return serialize( tree ). |
264 | 269 | replace( cssKEY, css + innerCss ).
|
265 | 270 | replace( jsKEY, js ).
|
266 | 271 | replace( appKEY, html ).
|
@@ -377,11 +382,11 @@ function layoutFor( path, content = {} ) {
|
377 | 382 | watcherReady = true;
|
378 | 383 | } )
|
379 | 384 | .on( 'error', err => console.log( 'ERROR:', err ) );
|
380 |
| - } |
381 |
| - |
382 |
| - const FiveServer = require( 'five-server' ).default; |
| 385 | + }; |
| 386 | + |
| 387 | + |
383 | 388 | serve &&
|
384 |
| - (await new FiveServer().start( { |
| 389 | + (await new FiveServer().start( { |
385 | 390 | open: true,
|
386 | 391 | workspace: __dirname,
|
387 | 392 | ignore: [...ignorePath, /\.(js|ts|svelte)$/, /\_layout\.html$/],
|
|
0 commit comments