Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dev mode hot reload and add sourcemaps #2402

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -54,6 +54,7 @@ async function build(opts) {
output: opts.globalName ? { name: opts.globalName } : {},
file: dest,
strict: false,
sourcemap: opts.sourcemap,
});
});
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion build/mincss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions server.configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const devConfig = {
files: ['CHANGELOG.md', 'docs/**/*', 'lib/**/*'],
port: 3000,
rewriteRules,
reloadDebounce: 1000,
reloadOnRestart: true,
server: {
...prodConfig.server,
routes: {
Expand Down
Loading