在我的entrerprise共享npm包中处理依赖的路径
发布时间:2020-12-14 04:50:45 所属栏目:百科 来源:网络整理
导读:我的公司中有一个共享包,它具有bootstrap作为依赖关系,结构如下所示: + - my-library + - node_modules + ... + bootstrap + scss --_mixins.scss --_functions.scss --_variables.scss --_buttons.scss +-scss -- _buttons.scss -- main.scss package.json
我的公司中有一个共享包,它具有bootstrap作为依赖关系,结构如下所示:
+ - my-library + - node_modules + ... + bootstrap + scss --_mixins.scss --_functions.scss --_variables.scss --_buttons.scss +-scss -- _buttons.scss -- main.scss package.json 这个库的想法将被许多团队消费. 的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"; @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 ... 当另一个项目消耗我的库时,问题就出现了.当有人做npm install –save my-library时,为get bootstrap定义的路径是不同的,因为bootstrap现在是一个向后的文件夹. + - consumer-project + - node_modules + ... + bootstrap + scss --_mixins.scss --_functions.scss --_variables.scss --_buttons.scss + - my-library +-scss -- _buttons.scss -- main.scss package.json 如果使用者项目导入main.scss文件,这将失败,因为现在_buttons.scss文件中的bootstrap路径现在是../node_modules/bootstrap/ 我的问题是: 解决方法
假设my-library位于node-modules中,使用–include-path选项引用./node_modules/,这将使node-sass在编译scss文件时能够找到引导程序.
将–include-path选项添加到package.json中的命令… "scripts": { "dev": "node-sass --include-path ./node_modules/ sass/index.scss -o --watch --output css" }, (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |