|
| 1 | +Sometimes you want to test the latest version of Docusaurus via `npm` or `yarn` without having to publish it to npm itself. For example, you may want to use the latest code in `master`. |
| 2 | + |
| 3 | +There are a couple of ways to use a local version of an npm package. |
| 4 | + |
| 5 | +## Install from a local Docusaurus repo |
| 6 | + |
| 7 | +> If you want to use the docusaurus-init script for testing, you will have to update the `initialize.js` file to point to the local Docusaurus repo instead of installing it from the npm server. In some ways, it is just easier to do the manual steps. |
| 8 | +
|
| 9 | +### Install the package from the Docusaurus repo |
| 10 | + |
| 11 | +``` |
| 12 | +cd /path/to/testing_project |
| 13 | +mkdir website # if this does not exist already |
| 14 | +cd website |
| 15 | +``` |
| 16 | + |
| 17 | +If you do not have a `package.json` file in the `website` directory, create one with the following content: |
| 18 | + |
| 19 | +``` |
| 20 | +{ |
| 21 | + "scripts": { |
| 22 | + "start": "docusaurus-start", |
| 23 | + "build": "docusaurus-build", |
| 24 | + "publish-gh-pages": "docusaurus-publish", |
| 25 | + "examples": "docusaurus-examples" |
| 26 | + } |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +Then: |
| 31 | + |
| 32 | +``` |
| 33 | +# Path to your Docusaurus clone |
| 34 | +npm install ../../path/to/docusaurus/ |
| 35 | +``` |
| 36 | + |
| 37 | +### Clowntown! |
| 38 | + |
| 39 | +Now, we have a bit of clowntown here in the way symlinks are handled. The above `npm install`, creates a `node_modules` directory with a symlink in it. And errors will result if you try to access the local site after starting the server (as you do below). You will get something like this error: |
| 40 | + |
| 41 | +``` |
| 42 | +Error: Couldn't find preset "react" relative to directory |
| 43 | +``` |
| 44 | + |
| 45 | +So, you should install these packages locally. **Base the versions on the versions defined in the Docusaurus `package.json`**. e.g., |
| 46 | + |
| 47 | +``` |
| 48 | +# Still in the website directory of the testing project |
| 49 | +npm install babel-preset-react@^6.24.0 |
| 50 | +npm install babel-preset-env@^1.6.0 |
| 51 | +npm install react@^15.5.4 |
| 52 | +``` |
| 53 | + |
| 54 | +### Test |
| 55 | + |
| 56 | +``` |
| 57 | +./node_modules/.bin/docusaurus-examples # or whatever you want to test, if anything |
| 58 | +./node_modules/.bin/docusaurus-start |
| 59 | +``` |
| 60 | + |
| 61 | +## Use Verdaccio |
| 62 | + |
| 63 | +Verdaccio is a good local npm server that you can use to test your packages. |
| 64 | + |
| 65 | +### Install verdaccio |
| 66 | + |
| 67 | +``` |
| 68 | +npm install --global verdaccio |
| 69 | +``` |
| 70 | + |
| 71 | +### Publish to verdaccio |
| 72 | + |
| 73 | +When you are ready to test the code that could make up the next version of your package, you can publish locally to verdaccio |
| 74 | + |
| 75 | +Run verdaccio in a **separate terminal window**: |
| 76 | + |
| 77 | +``` |
| 78 | +verdaccio |
| 79 | +``` |
| 80 | + |
| 81 | +In another terminal window, get ready to publish your local npm package: |
| 82 | + |
| 83 | +``` |
| 84 | +# Your clone of Docusaurus |
| 85 | +cd /path/to/docusaurus/ |
| 86 | +
|
| 87 | +# use anything for user, password, email |
| 88 | +# You should only have to do this once as long as you keep verdaccio installed |
| 89 | +npm adduser --registry http://localhost:4873 |
| 90 | +
|
| 91 | +npm publish --registry http://localhost:4873 |
| 92 | +``` |
| 93 | + |
| 94 | +You can navigate to localhost:4873 and you can see that your package was published. You can also see it showing you the steps you ran above as well. |
| 95 | + |
| 96 | +### Install the local npm package and test |
| 97 | + |
| 98 | +Now install the package in the repo you want to test Docusaurus on. |
| 99 | + |
| 100 | +``` |
| 101 | +cd /path/to/testing_project/ |
| 102 | +mkdir website # if this does not exist already |
| 103 | +cd website |
| 104 | +``` |
| 105 | + |
| 106 | +If you do not have a `package.json` file in the `website` directory, create one with the following content: |
| 107 | + |
| 108 | +``` |
| 109 | +{ |
| 110 | + "scripts": { |
| 111 | + "start": "docusaurus-start", |
| 112 | + "build": "docusaurus-build", |
| 113 | + "publish-gh-pages": "docusaurus-publish", |
| 114 | + "examples": "docusaurus-examples" |
| 115 | + } |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +Then: |
| 120 | + |
| 121 | +``` |
| 122 | +npm install docusaurus --registry http://localhost:4873 # this may be slower than the normal npm registry |
| 123 | +npm run examples # or whatever you want to test, if anything |
| 124 | +npm run start |
| 125 | +``` |
0 commit comments