Handling the path to the dependency in my entrePrise shared NPM package

There is a shared package in my company, which has bootstrap as a dependency, and the structure is as follows:

+ -my-library
+-node_modules
+ ...
+ bootstrap
+ scss
--_mixins.scss
--_functions.scss< br /> --_variables.scss
--_buttons.scss
+-scss
- _buttons.scss
- main.scss
package.json< /pre>

The idea of ​​this library will be consumed by many teams.
The main file of my library:

package.json

< pre>{
"name": "my-library",
"version": "1.0.0",
"description": "",
"scripts": {
"dev": "node-sass sass/index.scss --watch --output css"
},
"author": "",
"license" : "ISC",
"dependencies": {
"bootstrap": "^4.1.2"
},
"devDependencies": {
"node- sass": "^4.9.2"
}
}

SCSS / _buttons.scss

@import "./ node_modules/bootstrap/scss/_mixins";
@import "./node_modules/bootstrap/scss/ _functions";
@import "./node_modules/bootstrap/scss/_variables";
@import "./node_modules/bootstrap/scss/_buttons";

... THE CSS RULES FOR THE BUTTONS OF THE COMPANY ...

SCSS / main.scss

@import "_buttons";
.. . THE CSS RULES FOR GENERAL STYLES OF THE COMPANY ...

When another project consumes my library, the problem arises. When someone does npm install –save my-library, get bootstrap The defined path is different because bootstrap is now a backward folder.

+-consumer-project

+-node_modules
+ ...
+ bootstrap
+ scss
--_mixins.scss
--_functions.scss
--_variables.scss
- -_buttons.scss
+-my-library
+-scss
- _buttons.scss
- main.scss
package.json

< p>If the user project imports the main.scss file, this will fail, because the bootstrap path in the _buttons.scss file is now ../node_modules/bootstrap/

My question is:
What is the correct way to handle the dependency path of the library?

Assuming my-library is located in node-modules, use the –include-path option to reference. /node_modules /, this will enable node-sass to find the bootloader when compiling scss files.

Add the –include-path option to the command in package.json…

"scripts": {
"dev": "node-sass --include-path ./node_modules/ sass/index.scss -o --watch --output css"
},

There is a shared package in my company that has bootstrap as a dependency. The structure is as follows:

+-my-library
+-node_modules
+ ...
+ bootstrap
+ scss
--_mixins.scss
--_functions.scss
--_variables.scss
--_buttons.scss
+-scss
- _buttons.scss
- main.scss
package.json

The idea of ​​this library will be consumed by many teams.
The main file of my library:

package.json

{
"name": "my-library",
"version": "1.0.0",
"description": "",
"scripts": {
"dev": "node-sass sass/index.scss --watch --output css"
},
"author": "",
"license": "ISC",
"dependencies": {
"bootstrap": "^4.1.2"
},
"devDependencies": {
"node-sass": "^4.9.2"
}
}

SCSS / _buttons.scss

@import "./node_modules/bootstrap/scss/_mixins";
@import "./node_modules/bootstrap/scss/_functions";< br />@import "./node_modules/bootstrap/scss/_variables";
@import "./node_modules/bootstrap/scss/_buttons";

... THE CSS RULES FOR THE BUTTONS OF THE COMPANY ...

SCSS / main.scss

@import "_buttons";
... THE CSS RULES FOR GENERAL STYLES OF THE COMPANY ...

When another project consumes my library, the problem arises. When someone does npm install –save my-library, the path defined for get bootstrap is Different, because bootstrap is now a backward folder.

+-consumer-project

+-node_modules
+. ..
+ bootstrap
+ scss
--_mixins.scss
--_functions.scss
--_variables.scss
--_button s.scss
+-my-library
+-scss
- _buttons.scss
- main.scss
package.json

If the user project imports the main.scss file, this will fail because the bootstrap path in the _buttons.scss file is now ../node_modules/bootstrap/

My question is:
What is the correct way to handle the dependency path of the library?

Assuming my-library is located in node-modules, use the –include-path option to reference ./node_modules/, which will make node-sass compile scss files When you can find the boot program.

Add the –include-path option to the command in package.json…

"scripts": { 
"dev": "node-sass --include-path ./node_modules/ sass/index.scss -o --watch --output css"
},

Leave a Comment

Your email address will not be published.