Migrate from v1 to v2
The primary goal of the version update to v2 is:
- Update to VitePress
1.0.0. - Enforce all packages and modules follow the same code structure, naming conventions, imports/exports pattern.
Therefore,
- All the updated packages will not compatible with VitePress RC versions anymore.
- All the updated packages will follow:
- Exported entry file is
{packageName}/clientif it is a Vue component, Vue plugin, client side code, styles, etc. - Exported entry file is
{packageName}/localesif it is a i18n module. - Exported entry file is
{packageName}/vitepressif it is a VitePress specific plugin (e.g. build hook,buildEnd,transformHTML, etc.) - Exported entry file is
{packageName}/markdown-itif it is a markdown-it plugin. - Exported entry file is
{packageName}/viteif it is a Vite plugin.
- All the updated packages will follow the same i18n guidelines across Nolebase packages.
- All the updated packages will try to re-use their Vue components from
@nolebase/uipackage.
And breaking changes will be introduced, but with a migration guide, and less migration effort.
Inline links previewing
There are some breaking changes in the @nolebase/vitepress-plugin-inline-link-preview plugin.
- No longer require the use of
@nolebase/markdown-it-element-transformpackage, the new@nolebase/vitepress-plugin-inline-link-preview/markdown-itplugin will export the needed markdown-it plugin as a function that exported from@nolebase/vitepress-plugin-inline-link-preview/markdown-it. - By following the new structure, the new
@nolebase/vitepress-plugin-inline-link-preview/clientwill export the Vue component for the inline link previewing instead of the direct import from the package root.
Remove @nolebase/markdown-it-element-transform
{
"devDependencies": {
"@nolebase/markdown-it-element-transform": "^1.28.0"
}
}You can perform the following steps to remove the @nolebase/markdown-it-element-transform package:
nun @nolebase/markdown-it-element-transformpnpm uninstall @nolebase/markdown-it-element-transformyarn remove @nolebase/markdown-it-element-transformnpm uninstall @nolebase/markdown-it-element-transformUpdate VitePress config to use the new markdown-it plugin exported from @nolebase/vitepress-plugin-inline-link-preview/markdown-it
You can now use
import { defineConfig } from 'vitepress'
import { InlineLinkPreviewElementTransform } from '@nolebase/vitepress-plugin-inline-link-preview/markdown-it'
export default defineConfig({
// ...
markdown: {
// ...
config: (md) => {
md.use(InlineLinkPreviewElementTransform)
},
},
})to replace the old way of using @nolebase/markdown-it-element-transform.
Full changes:
import { defineConfig } from 'vitepress'
import { ElementTransform } from '@nolebase/markdown-it-element-transform'
import type { Options as ElementTransformOptions } from '@nolebase/markdown-it-element-transform'
import { InlineLinkPreviewElementTransform } from '@nolebase/vitepress-plugin-inline-link-preview/markdown-it'
export default defineConfig({
// ...
markdown: {
// ...
config: (md) => {
md.use(ElementTransform, (() => {
let transformNextLinkCloseToken = false
return {
transform(token) {
switch (token.type) {
case 'link_open':
if (token.attrGet('class') !== 'header-anchor') {
token.tag = 'VPNolebaseInlineLinkPreview'
transformNextLinkCloseToken = true
}
break
case 'link_close':
if (transformNextLinkCloseToken) {
token.tag = 'VPNolebaseInlineLinkPreview'
transformNextLinkCloseToken = false
}
break
}
},
} as ElementTransformOptions
})())
md.use(InlineLinkPreviewElementTransform)
},
},
})Update VitePress theme config to use the new Vue component exported from @nolebase/vitepress-plugin-inline-link-preview/client
Since all the Vue components are now exported from the client entry file, you can now use
import {
NolebaseInlineLinkPreviewPlugin,
} from '@nolebase/vitepress-plugin-inline-link-preview'
} from '@nolebase/vitepress-plugin-inline-link-preview/client'to replace the old way of using @nolebase/vitepress-plugin-inline-link-preview.
The same applies to the styles:
import '@nolebase/vitepress-plugin-inline-link-preview/dist/style.css'
import '@nolebase/vitepress-plugin-inline-link-preview/client/style.css'Enhanced readabilities
There are some breaking changes in the @nolebase/vitepress-plugin-enhanced-readabilities plugin.
- By following the new structure, the new
@nolebase/vitepress-plugin-enhanced-readabilities/clientwill export the Vue components for the enhanced readabilities instead of the direct import from the package root.
Update VitePress theme config to use the new Vue components exported from @nolebase/vitepress-plugin-enhanced-readabilities/client
Since all the Vue components are now exported from the client entry file, you can now use
import {
InjectionKey as NolebaseEnhancedReadabilitiesInjectionKey,
LayoutMode as NolebaseEnhancedReadabilitiesLayoutMode,
NolebaseEnhancedReadabilitiesMenu,
NolebaseEnhancedReadabilitiesScreenMenu,
} from '@nolebase/vitepress-plugin-enhanced-readabilities'
} from '@nolebase/vitepress-plugin-enhanced-readabilities/client'to replace the old way of using @nolebase/vitepress-plugin-enhanced-readabilities.
The same applies to the styles:
import '@nolebase/vitepress-plugin-enhanced-readabilities/dist/style.css'
import '@nolebase/vitepress-plugin-enhanced-readabilities/client/style.css'Highlight targeted heading
There are some breaking changes in the @nolebase/vitepress-plugin-highlight-targeted-heading plugin.
- By following the new structure, the new
@nolebase/vitepress-plugin-highlight-targeted-heading/clientwill export the Vue components for the highlight targeted heading instead of the direct import from the package root.
Update VitePress theme config to use the new Vue components exported from @nolebase/vitepress-plugin-highlight-targeted-heading/client
Since all the Vue components are now exported from the client entry file, you can now use
import {
NolebaseHighlightTargetedHeading,
} from '@nolebase/vitepress-plugin-highlight-targeted-heading'
} from '@nolebase/vitepress-plugin-highlight-targeted-heading/client'to replace the old way of using @nolebase/vitepress-plugin-highlight-targeted-heading.
The same applies to the styles:
import '@nolebase/vitepress-plugin-highlight-targeted-heading/dist/style.css'
import '@nolebase/vitepress-plugin-highlight-targeted-heading/client/style.css'Git-based page histories
UI config
mapContributorsnow deprecated, please usemapAuthorsinstead since it's more neutral for writers.nameAliasesnow deprecated, please usemapByNameAliasesinstead, which is more clear and consistent with other plugins.emailAliasesnow deprecated, please usemapByEmailAliasesinstead, which is more clear and consistent with other plugins.- Added new
usernamefield, which is the username of the author on GitHub used to fetch the avatar. - The
localesin the original Vite pluginGitChangelogMarkdownSectionno longer need to be configured and have been migrated to the UI configuration underlocales:changelog.titlecontributors.title;
- In order to better structure the organization of the i18n fields, the original
noLogsi18n configuration changed tochangelog.noData;noContributorsi18n configuration was changed tocontributors.noData.lastEditedi18n Configuration changed tolastEdited.lastEditedDateFnsLocaleNameconfiguration changed tochangelog.lastEditedDateFnsLocaleNameviewFullHistoryi18n Configuration changed tochangelog.viewFullHistorycommittedOni18n configuration changed tochangelog.committedOn
Vite config
- There is no longer a need to configure the
localesfield forGitChangelogMarkdownSection, and all of the internationalized i18n configuration has been migrated to the UI configuration. includeDirsandincludeExtensionshave been deprecated and merged intoinclude, which is a list of glob modes with!negation.- If a renderable page file located outside of the VitePress root (where
.vitepresslives), please configure thecwd(current working directory) to the parent directory of the page files. (For example, in a Monorepo, if the source file that rendered a page s located outside ofdocs/, you need to setcwdto the root directory of the Monorepo instead of the root of VitePress.) - No longer needed to configure
rewritePaths, thereforrewritePathsis now deprecated, can be safely removed. rewritePathsBypattern should be configured in the against to filesystem paths, not the URL route paths.
Previewing image (social media card) generation
There are some breaking changes in the @nolebase/vitepress-plugin-og-image plugin.
- By following the new structure, the new
@nolebase/vitepress-plugin-og-image/vitepresswill export the VitePress specific plugin instead of the direct import from the package root.
Update VitePress config to use the new VitePress specific plugin exported from @nolebase/vitepress-plugin-og-image/vitepress
You can now use
import { buildEndGenerateOpenGraphImages } from '@nolebase/vitepress-plugin-og-image'
import { buildEndGenerateOpenGraphImages } from '@nolebase/vitepress-plugin-og-image/vitepress'to replace the old way of using @nolebase/vitepress-plugin-og-image.
Conclusion
- Rewrite all the import paths to follow the new structure.
- Remove the old packages that are no longer needed.
That's it! Nothing else were impacted for the migration from v1 to v2.
We have improved the code structure, naming conventions, imports/exports pattern, and made the packages more consistent across the Nolebase ecosystem. Happy writing! 🎉
See you next time in the v3 migration guide!
Neko
Northword
BeiyanYunyi