From 947d8decb8c5c62f3ce50d0c6ac0e27bb6c7a6b5 Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Tue, 16 Apr 2024 22:52:48 -0500 Subject: [PATCH] fix: dev mode hot reload and add sourcemaps (#2402) --------- Co-authored-by: Koy Zhuang Co-authored-by: sy-records <52o@qq52o.cn> --- build/build.js | 41 ++++++++++++++++++++--------------------- build/mincss.js | 2 +- server.configs.js | 2 ++ 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/build/build.js b/build/build.js index c8b9ab5..ceb5d7a 100644 --- a/build/build.js +++ b/build/build.js @@ -3,8 +3,8 @@ import { promises as fs } from 'fs'; import * as rollup from 'rollup'; import commonjs from '@rollup/plugin-commonjs'; import nodeResolve from '@rollup/plugin-node-resolve'; -import uglify from '@rollup/plugin-terser'; import replace from '@rollup/plugin-replace'; +import terser from '@rollup/plugin-terser'; import chokidar from 'chokidar'; import { relative } from './util.js'; @@ -54,6 +54,7 @@ async function build(opts) { output: opts.globalName ? { name: opts.globalName } : {}, file: dest, strict: false, + sourcemap: opts.sourcemap, }); }); } @@ -68,15 +69,14 @@ async function buildCore() { }) ); - if (isProd) { - promises.push( - build({ - input: 'src/core/index.js', - output: 'docsify.min.js', - plugins: [uglify()], - }) - ); - } + promises.push( + build({ + input: 'src/core/index.js', + output: 'docsify.min.js', + plugins: [terser()], + sourcemap: true, + }) + ); await Promise.all(promises); } @@ -102,17 +102,16 @@ async function buildAllPlugin() { }); }); - if (isProd) { - plugins.forEach(item => { - promises.push( - build({ - input: 'src/plugins/' + item.input, - output: 'plugins/' + item.name + '.min.js', - plugins: [uglify()], - }) - ); - }); - } + plugins.forEach(item => { + promises.push( + build({ + input: 'src/plugins/' + item.input, + output: 'plugins/' + item.name + '.min.js', + plugins: [terser()], + sourcemap: true, + }) + ); + }); await Promise.all(promises); } diff --git a/build/mincss.js b/build/mincss.js index 3d480c1..45c0dc1 100644 --- a/build/mincss.js +++ b/build/mincss.js @@ -9,7 +9,7 @@ const files = fs files.forEach(file => { file = path.resolve('lib/themes', file); cssnano - .process(fs.readFileSync(file)) + .process(fs.readFileSync(file), { from: file }) .then(result => { file = file.replace(/\.css$/, '.min.css'); fs.writeFileSync(file, result.css); diff --git a/server.configs.js b/server.configs.js index 2f0889c..0360bd6 100644 --- a/server.configs.js +++ b/server.configs.js @@ -24,6 +24,8 @@ export const devConfig = { files: ['CHANGELOG.md', 'docs/**/*', 'lib/**/*'], port: 3000, rewriteRules, + reloadDebounce: 1000, + reloadOnRestart: true, server: { ...prodConfig.server, routes: {