nodebb.org/blog/migration-guide-for-v2.html

165 lines
20 KiB
HTML
Raw Normal View History

2025-04-13 19:04:51 -04:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
2025-04-22 11:11:36 -04:00
<title>Migration Guide for v2 - NodeBB - Modern Forum Software</title>
2025-04-13 19:04:51 -04:00
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Blog of NodeBB Forum Software - The Modern Discussion Platform">
<meta name="author" content="NodeBB Inc.">
<meta name="keywords" content="nodebb, node.js, forum, discussion, community, software, hosting, blog">
<link rel="apple-touch-icon" sizes="180x180" href="/images/icons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/icons/32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/icons/16x16.png">
<link rel="shortcut icon" href="/images/icons/favicon.ico">
<!-- Google Fonts: Inter & Poppins -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&family=Poppins:wght@400;600&display=swap" rel="stylesheet">
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<!-- Font Awesome -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- our css-->
<link href="/css/style.css" rel="stylesheet">
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-V0P62EB8Q6"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-V0P62EB8Q6');
</script>
</head>
<body class="p-0 py-5 p-lg-5">
<!-- Navbar -->
<nav class="navbar navbar-expand-lg bg-body fixed-top shadow-sm">
<div class="container-lg">
<a class="navbar-brand py-2" href="/">
<img src="/images/brand/nodebb-logo.svg" style="height: 36px; width: auto;" alt="NodeBB Logo" />
</a>
<button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navbarMenu" aria-controls="navbarMenu" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarMenu">
<ul class="nav nav-underline gap-4 flex-column flex-lg-row align-items-end align-items-lg-center mt-4 mt-lg-0">
<li class="nav-item">
2025-04-13 19:23:27 -04:00
<a href="/" class="nav-link text-reset fw-semibold">HOME</a>
2025-04-13 19:04:51 -04:00
</li>
<li class="nav-item">
<a href="/product" class="nav-link text-reset fw-semibold">PRODUCT</a>
</li>
<li class="nav-item">
<a href="/pricing" class="nav-link text-reset fw-semibold">PRICING</a>
</li>
<li class="nav-item">
<a href="/services" class="nav-link text-reset fw-semibold">SERVICES</a>
</li>
<li class="nav-item dropdown">
<a href="#" target="_blank" role="button" data-bs-toggle="dropdown" aria-expanded="false" class="nav-link dropdown-toggle text-reset fw-semibold">RESOURCES</a>
<ul class="dropdown-menu dropdown-menu-end border-0 shadow p-1">
<li><a href="https://community.nodebb.org/" class="dropdown-item rounded-1" target="_blank">Community</a></li>
<li><a href="https://try.nodebb.org/" class="dropdown-item rounded-1" target="_blank">Demo Site</a></li>
<li><a href="https://community.nodebb.org/category/28/answers" class="dropdown-item rounded-1" target="_blank">Answers</a></li>
<li><a href="https://docs.nodebb.org/" class="dropdown-item rounded-1" target="_blank">Documentation</a></li>
<li><a href="/bounty" class="dropdown-item rounded-1">Bug Bounty</a></li>
</ul>
</li>
<li class="nav-item">
<a href="/contact" class="btn btn-warning rounded-pill">Contact Us</a>
</li>
<li class="nav-item">
<a href="https://manage.nodebb.org/register" class="btn btn-primary"><i class="fa-solid fa-rocket"></i> Start Free Trial</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Page Content -->
<div class="container-lg mt-5">
<!-- Home -->
<div id="home-tab-pane">
<div class="row pt-2 pt-lg-5">
<div class="col-12 d-flex flex-column gap-4">
<h1 class="display-1 fw-bold fs-1">
Migration Guide for v2
</h1>
2025-04-22 11:11:36 -04:00
2025-04-13 19:04:51 -04:00
</div>
</div>
<!-- blog post -->
<div class="py-5">
<div class="d-flex gap-2 align-items-center mb-4">
<a href="https://community.nodebb.org/user/julian"><img class="rounded-circle" width="32" src="https://community.nodebb.org/assets/uploads/profile/uid-2/2-profileavatar-1738544541106.jpeg"></a> <a href="https://community.nodebb.org/user/julian" class="fw-semibold">Julian Lam</a> <span class="text-secondary">2/23/2022, 11:36:58 AM</span>
</div>
<div class="">
<h2>v2 Migration Guide</h2><p>In advance of the release of version 2, we are releasing this guide in order to give third-party developers a chance to bring their plugins and themes up-to-date. In the successive sections below, we will outline the breaking change or new best-practice, and the steps to migrate, along with a live example.</p> <h4>This blog post is the third in a series of posts related to the release of NodeBB v2</h4> <p><p><em>We tried to plan out this release in such a way that any breaking changes would be minimized. There is a chance that your theme or plugin will just work out-of-the-box, or with minimal changes.</em></p><p><em>We've tried to list any gotchas and necessary changes in this article, but please do let us know if you encounter one we haven't seen yet.</em></p></p><h3>Migrate AMD modules from <code>scripts</code> and <code>acpScripts</code> to <code>modules</code> (breaking change 🚨)</h3><p>Standard practice in v1.x was to write a page-specific client-side script or admin script as an AMD module, and bundle them with the minified files served to the browser. We now recommend that the files be defined in the <code>modules</code> property in <code>package.json</code> so that they can be bundled as necessary, or dynamically loaded otherwise.</p><p><strong>Note:</strong>These scripts can continue to be written in AMD-style, as it is supported by Webpack.</p><h4>Live example (nodebb-theme-persona)</h4><p>The persona theme contains two page-specific scripts, one loaded on the user settings page, and another loaded in the ACP settings page.</p><ul><li>The <a href=\"https://github.com/NodeBB/nodebb-theme-persona/pull/545/files#diff-7b32f67ab72ef7b295c60be75ff703b7660e0f7e737e77251e5cc69deb7844aaL12-L22\">scripts are removed from the <code>scripts</code> and <code>acpScripts</code> sections, and added to <code>modules</code></a></li><li>Note that the key for these modules matches the template name, and that it is prepended with <code>../</code> -- this is necessary because they are not added to the modules folder</li><li>Modules can continue to be written in AMD-style, this is handled transparently by Webpack.</li></ul><h3>Migrate third-party modules to use npm dependencies, if available (best practice)</h3><p>Any third-party modules are no longer recommended to be used in the <code>modules</code> section of <code>plugin.json</code>. Instead, install them directly from npm  if available, and just import them into your client-side code.</p><p>There are some savings to be had by no longer appending third-party code into the main bundle. Webpack can choose to either bundle it in, or dynamically load it as-needed.</p><p>Additionally, having a dependency maintained in your <code>package.json</code> allows for better version control and updates, without needing to modify copy-pasted code directly in your repository.</p><h4>Live example (nodebb-plugin-markdown)</h4><p>The markdown plugin relies on <code>highlightjs</code> as a dependency in order to highlight code written in code blocks.</p><ul><li>The plugin is now <a href=\"https://github.com/julianlam/nodebb-plugin-markdown/pull/209/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L32-R32\">installed directly from npm</a>, instead of the CDN variant, and</li><li>Instead of <code>require</code>-ing them as an AMD module, <a href=\"https://github.com/julianlam/nodebb-plugin-markdown/pull/209/files#diff-c3eb992fbaa0b603cd6f9ab34aff720e723fbedd4b64065482d463a9a892d7d5L212-R214\">they are now imported in by Webpack</a></li></ul><h4>Live example (nodebb-plugin-2factor)</h4><p>The 2factor plugin relies on <a href=\"https://github.com/github/webauthn-json\">@github/webauthn-json</a> to properly encode and verify key registrations and challenges.</p><ul><li><a href=\"https://github.com/NodeBB/nodebb-plugin-2factor/pull/73/files#diff-7b32f67ab72ef7b295c60be75ff703b7660e0f7e737e77251e5cc69deb7844aaL28\">The script is removed from scripts configurat
</div>
</div>
</div>
<hr class="my-5"/>
<!-- FOOTER -->
<footer>
<div class="d-flex flex-column flex-md-row gap-5 justify-content-between mb-5 flex-wrap">
<div class="d-flex flex-column">
<h5 class="fw-bold">Get Started</h5>
<ul class="list-unstyled">
<li><a href="/product" class="link-secondary text-decoration-none">PRODUCT</a></li>
<li><a href="/pricing" class="link-secondary text-decoration-none">PRICING</a></li>
<li><a href="/services" class="link-secondary text-decoration-none">SERVICES</a></li>
</ul>
</div>
<div class="d-flex flex-column">
<h5 class="fw-bold">Resources</h5>
<ul class="list-unstyled">
<li><a href="https://community.nodebb.org/" class="link-secondary text-decoration-none" target="_blank">COMMUNITY</a></li>
<li><a href="https://try.nodebb.org/" class="link-secondary text-decoration-none" target="_blank">DEMO SITE</a></li>
<li><a href="https://community.nodebb.org/category/28/answers" class="link-secondary text-decoration-none" target="_blank">ANSWERS</a></li>
<li><a href="https://docs.nodebb.org" class="link-secondary text-decoration-none" target="_blank">DOCUMENTATION</a></li>
<li><a href="/bounty" class="link-secondary text-decoration-none">BUG BOUNTY</a></li>
</ul>
</div>
<div class="d-flex flex-column">
<h5 class="fw-bold">Company</h5>
<ul class="list-unstyled">
<li><a href="/about" class="link-secondary text-decoration-none">ABOUT</a></li>
<li><a href="/blog" class="link-secondary text-decoration-none">BLOG</a></li>
<li><a href="/contact" class="link-secondary text-decoration-none">CONTACT</a></li>
</ul>
</div>
<div class="d-flex flex-column">
<a href="https://manage.nodebb.org/register" class="btn btn-primary"><i class="fa-solid fa-rocket"></i> Start Free Trial</a>
<div class="d-flex gap-3 mt-3 justify-content-between px-2">
<a title="NodeBB Github Page" href="https://github.com/nodebb/nodebb" class="link-secondary text-decoration-none"><i class="fab fa-github"></i></a>
<a title="NodeBB Twitter Page" href="https://twitter.com/nodebb" class="link-secondary text-decoration-none"><i class="fab fa-twitter"></i></a>
<a title="NodeBB Mastodon Page" href="https://fosstodon.org/@nodebb" class="link-secondary text-decoration-none"><i class="fa-brands fa-mastodon"></i></a>
<a title="NodeBB Facebook Page" href="https://www.facebook.com/NodeBB" class="link-secondary text-decoration-none"><i class="fab fa-facebook"></i></a>
</div>
</div>
</div>
<div class="d-flex flex-wrap justify-content-between gap-5 small">
<span class="text-secondary text-nowrap">©2025 NodeBB, Inc. — Made in Canada with <i class="fa-solid fa-heart text-danger"></i>.</span>
<div class="d-flex gap-3">
<a href="/tos" class="link-secondary text-nowrap text-decoration-none">Terms of Service</a>
<a href="/privacy" class="link-secondary text-nowrap text-decoration-none">Privacy Policy</a>
<a href="/gdpr" class="link-secondary text-nowrap text-decoration-none">GDPR</a>
<a href="/dmca" class="link-secondary text-nowrap text-decoration-none">DMCA</a>
</div>
</div>
</footer>
</div>
<!-- Bootstrap 5 JS Bundle (includes Popper) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
</body>
</html>