【发布时间】:2018-06-23 11:37:46
【问题描述】:
我添加了包
yarn add themify-icons-sass
然后在我的组件中,我将它导入到脚本和样式中
<script>
....
import 'themify-icons-sass'
<style lang="scss" scoped>
@import 'themify-icons-sass/themify-icons';
...
但我得到一个构建错误
This dependency was not found:
* themify-icons-sass in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/HelloWorld.vue
To install it, you can run: npm install --save themify-icons-sass
我在哪里输入错误?感谢反馈
更新
首先,如果我想从 ./node_modules 导入它,那么 @import 不应该是范围样式...
所以我将它移到了我的 App.vue 中的全局样式
<style lang="scss">
@import "~themify-icons-scss/scss/themify-icons.scss";
#app { ...
然后我得到一个错误,node-sass/vendor 目录没有被构建..所以我添加重建 node_sass
yarn add node-sass --force
现在它正在考虑包,但我收到另一个与字体的相对路径相关的错误:
These relative modules were not found:
* ../fonts/themify.eot in ./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-7ba5bd90","scoped":false,"hasInlineConfig":false}!./node_modules/sass-loader/lib/loader.js?{"sourceMap":true}!./node_modules/vue-
loader/lib/selector.js?type=styles&index=0!./src/App.vue
* ../fonts/themify.eot?-fvbane in ./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-7ba5bd90","scoped":false,"hasIn
lineConfig":false}!./node_modules/sass-loader/lib/loader.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue
* ../fonts/themify.svg?-fvbane in ./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-7ba5bd90","scoped":false,"hasIn
lineConfig":false}!./node_modules/sass-loader/lib/loader.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue
* ../fonts/themify.ttf?-fvbane in ./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-7ba5bd90","scoped":false,"hasInlineConfig":false}!./node_modules/sass-loader/lib/loader.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue
* ../fonts/themify.woff?-fvbane in ./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-7ba5bd90","scoped":false,"hasInlineConfig":false}!./node_modules/sass-loader/lib/loader.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue
themify-icons-scss 文件结构如下:
node_modules/themify-icons-scss
fonts
themify.eot
themify.svg
themify.ttf
themify.woff
scss
_core.scss
_extras.scss
_icons.scss
_mixins.scss
_paths.scss
_variables.scss
themify-icons.scss
node_modules/themify-icons-scss/scss/themify-icons.scss
@import "variables";
@import "mixins";
@import "path";
@import "core";
@import "extras";
@import "icons";
themify-icons-scss/scss/_path.scss
@font-face { 字体系列:“主题化”; src:url('#{$ti-font-path}/themify.eot?-fvbane'); src:url('#{$ti-font-path}/themify.eot?#iefix-fvbane') 格式('embedded-opentype'), url('#{$ti-font-path}/themify.woff?-fvbane') 格式('woff'), url('#{$ti-font-path}//themify.ttf?-fvbane') 格式('truetype'), url('#{$ti-font-path}/themify.svg?-fvbane#themify') 格式('svg'); 字体粗细:正常; 字体样式:正常;
这是存在一些问题的地方...变量中定义的 $ti-font-path 相对于包中的 scss 目录..
themify-icons-scss/scss/_variables.scss
$ti-font-path: "../fonts" !default;
$ti-class-prefix: "ti" !default;
}
【问题讨论】: