fix: dev mode hot reload and add sourcemaps (#2402)

---------

Co-authored-by: Koy Zhuang <koy@ko8e24.top>
Co-authored-by: sy-records <52o@qq52o.cn>
This commit is contained in:
John Hildenbiddle 2024-04-16 22:52:48 -05:00 committed by GitHub
parent a3ab2be0b0
commit 947d8decb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 22 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -24,6 +24,8 @@ export const devConfig = {
files: ['CHANGELOG.md', 'docs/**/*', 'lib/**/*'],
port: 3000,
rewriteRules,
reloadDebounce: 1000,
reloadOnRestart: true,
server: {
...prodConfig.server,
routes: {