Offline Search for Docusaurus V2
- Install this package
npm i docusaurus-lunr-search --save
- Then run docusaurus swizzle
npm run swizzle docusaurus-lunr-search SearchBar
- Add the docusaurus-lunr-search plugin to your
docusaurus.config.js
const path = require('path');
module.exports = {
// ...
plugins: [path.resolve(__dirname, './node_modules/docusaurus-lunr-search/')],
}
- Then build your Docusaurus project
npm run build
- Serve your application
npx http-server ./build
Note: Docusaurus search information can only be generated from a production build. Local development is currently not supported.
const path = require('path');
module.exports = {
// ...
plugins: [[ path.resolve(__dirname, './node_modules/docusaurus-lunr-search/'), {
languages:['en', 'de'] // language codes
}],
}
Supports all the language listed here https://github.com/MihaiValentin/lunr-languages
Thanks to algolia/docsearch.js
, I modified it to create this search component
And thanks cmfcmf, I used the code from his library docusaurus-search-local for multi-language support.