P
P
pqgg7nwkd42021-05-11 19:13:36
Node.js
pqgg7nwkd4, 2021-05-11 19:13:36

How to use developments in node that are not in the project folder?

Something like this structure:

наработки/some.js

проект1/package.json
проект1/node_modules/...
проект1/...
проект1/index.js


Inside index.js, I want to use the developments not as a module, but simply as source code. I want the development dependencies to be resolved according to the project settings.
I do require('../developments/some.js').
But node doesn't look for development dependencies in the same project/node_modules/.

Partially, the problem can be solved using a symlink and prohibiting node from denaming symlinks, but this does not suit me either - there are problems when debugging and in the IDE.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vItalIyIrtlach, 2021-05-11
@w13vitaliy

Perhaps you can use lerna

P
pqgg7nwkd4, 2021-05-12
@pqgg7nwkd4

I decided as follows:
1. To use the developments in the webpack.config.js script itself, I registered the NODE_PATH=./node_modules environment variable in package.json:

{
  "private": true,
  "scripts": {
    "dev-debug": "NODE_PATH=./node_modules node --inspect-brk ./node_modules/.bin/webpack --devtool none --mode development",
    "prod-debug": "NODE_PATH=./node_modules node --inspect-brk ./node_modules/.bin/webpack --mode production",
    "dev-server": "NODE_PATH=./node_modules ./node_modules/.bin/webpack serve --mode development",
    "prod": "NODE_PATH=./node_modules ./node_modules/.bin/webpack --mode production"
  },

2. And in order to use it in the application, I wrote it similarly in the webpack.config.js file:
resolve: {
            alias: {
                наработки: __dirname + "/../../../наработки",
            },
            modules: [__dirname + '/node_modules'], // - вот
        },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question