Importing sass from node_modules with vue plugin
See original GitHub issueHello! I’m trying to use vue plugin and importing sass from node_modules there with ‘~’ syntax. It’s important for me to use that syntax and not relative ‘./node_modules/…’ because the component is a part of the library and I want it to be importable as a .vue file (along with bili build).
<template>
<a class="button is-primary">Button</a>
</template>
<script>
module.exports = {
name: 'button-example',
};
</script>
<style lang="scss" scoped>
@import "~bulma/bulma";
</style>
When I’m running bili on that file I get the error:
⋊> ~/p/bili-sass-import-tilde-example npm run build 12:51:03
> bili-sass-import-tilde-example@0.1.0 build /home/larionov/projects/bili-sass-import-tilde-example
> bili --plugins.vue --format=cjs,esm,umd --module-name=Example
error Failed to bundle src/index.js in cjs format
Stack Trace:
Error: Error: File to import not found or unreadable: ~bulma/bulma.
at Promise.all.descriptor.styles.map (/home/larionov/projects/bili-sass-import-tilde-example/node_modules/rollup-plugin-vue/dist/rollup-plugin-vue.js:241:31)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bili-sass-import-tilde-example@0.1.0 build: `bili --plugins.vue --format=cjs,esm,umd --module-name=Example`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bili-sass-import-tilde-example@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/larionov/.npm/_logs/2019-03-22T05_51_07_306Z-debug.log
Here is a minimal repository where the error can be reproduced: https://github.com/larionov/bili-vue-sass-import-tilde-example
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to add sass loader for node_modules in vue.config.js
Try this, from the docs: @import "~my-node-module/theme/engine.scss";. The ~ tells Webpack that the import path is not a relative path.
Read more >Using Pre-Processors - Vue Loader
Now in addition to being able to import 'style.scss' , we can use SCSS in Vue ... if you import a Vue SFC...
Read more >sass-loader - webpack - JS.ORG
The sass-loader uses Sass's custom importer feature to pass all queries to the Webpack resolving engine. Thus you can import your Sass modules...
Read more >Getting Started | BootstrapVue
import Vue from 'vue' import { BootstrapVue, IconsPlugin } from ... SCSS files (order is important) @import 'node_modules/bootstrap/scss/bootstrap.scss'; ...
Read more >Bootstrap & Vite
Set up Bootstrap's Sass import in vite.config.js . ... You can also import JavaScript plugins individually as needed to keep bundle sizes down:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We went with
magic-importer
:bili.config.js
You can use https://rollup-plugin-vue.vuejs.org/options.html#style-preprocessoptions to set sass options,
~
is implemented in rollup-plugin-postcss via theimporter
option: https://github.com/egoist/rollup-plugin-postcss/blob/e63c9ae659fe4e982fa8d31c955767c2a5e6e98f/src/sass-loader.js#L38I’ll try to make bili support this by default, not anytime soon though.