I would like to create a npm repo containing a folder with Vue single file components from which I can import then easily:
import { Button } from "#user/design-system"
the problem I have is that the Button.vue contains variables coming from a global .scss file that is handled by Webpack.
How can I bake the variables into each component when I build for the npm release?
So essentially I want a dev environment which I run by npm run serve and I want a npm run build which copies all components and bakes the CSS variables into it to have stand-alone components.
You should have this variables in a dedicated file (for example _variables.scss), in your project where you want to import your component. Then you should make this variables accessible to all the components. I suggest you to use style-resouces-loader, that will import your variable in every component. Vue ClI wrapper - vue-cli-plugin-style-resources-loader.
To export your UI library with already inlined CSS, you should build your UI library through vue-cli-service build. And then you can import your builded component with builded CSS styles, which was built from SCSS.
Related
I have a Vue.js application that imports private npm packages that are Vue.js libraries:
// Vue.js app
import { someComponent } from '#private-npm/some-library';
The someComponent has some code that looks as such:
// someComponent
const username = process.env.USERNAME;
When I build some-library, so that I can publish it to my private repo, it writes the process environment variables in plain text inside the bundle file.
So my concerns:
Even though my npm is private, I feels like bad practice to have my environment variables written to the module which someone can install and view inside node_modules.
I need to be able to build the Vue.js app that uses the library with different environment variables
So, in summary, I need my bundled library to not import the real value of the process environment variable and instead leave it as process.env.USERNAME so when the Vue.js app builds it can dynamically change that variable via a .env.
I am trying to create a Vue.js component library, which will later be released on npm for future projects of mine to use it. However, I would like the components to have default scss variables, AKA variables marked with the !default flag. Then, whenever I use the component library in a new project I would like to have the ability for the component library to use a unique scss file which may contain overwrites to the scss variables.
I know to add scss file to the libraries vue.config.js file (I am using vue-cli 3) for each component to pull in that file. However, I cannot figure out how to have vue's configuration to use both the default varaiables file and a project's variables file to "merge" the scss variables. This may be more of a webpack question than a vue question.
I am building a webcomponent package using Vue CLI 3 and single file components. We have a shared package our-awesome-shared-controls that contain basic site components such as a collapsible container.
Inside my component, I import and reference the collapsible container and wrap my content in it. When I build as an app the styles from the imported components are included and everything looks great, however; when I target wc (WebComponent) using the vue-cli the style for the imported component (collapsible container) are not included.
Is there a way for me to tell the vue cli that it should include those styles? If not would there be a way to import those styles? The imported components have their style set to scoped so I'm not sure if that makes a difference.
How can a .vue file (as a parent component with child .vue files) be published to npm so that you can install, require, and use it as a component with browserify as
let component = require('published-vue-component');
I only use browserify; I don't use webpack at all. I thus bundle all .vue files into a single build.js using a vueify transform. All of the information I see currently about this either a.) reads that you should export your main .vue file (doesn't work) or b.) involves webpack.
If you go ahead and bundle the component with a vueify transform and set "main": "the/bundle/path/index.js", it seems that a vueify transform can't work without a template rendering function and thus isn't intended for single components.
If you simply export the parent .vue file, when you require the component you're going to get a syntax error from the first character of the <template> tag.
If you bundle your component as a umd module, then you can import it into browserify or webpack. Use rollup and this plugin: http://vuejs.github.io/rollup-plugin-vue/
I ran into this issue with my vue-autosuggest library, where browserify users were experiencing issues importing my module.
Check out this example rollup config for inspiration:
https://github.com/Educents/vue-autosuggest/blob/master/build/rollup.umd.config.js
Hope this helps!
I am trying to create a plugin that utilizes components from another Vuejs plugin (Vuetify). Basically, I have some common components I want to share across multiple applications with our company.
I thought it would just be a matter of:
Create a github repo for the shared components
Author the plugin
Reference the repo in consuming apps via npm install
Here is the gist of the plugin:
// src/index.js <-- package.json/main is set to "src"
import MyComponent from "./MyComponent.vue";
import * as api from "./api";
export default function install(Vue) {
Vue.component("myComponent", MyComponent );
Vue.prototype.$myApi = api;
}
At the moment, the behavior I'm seeing is:
GOOD
plugin install function is being executed
functions from api attached to Vue.prototype are available in app components
my-component is available in the app and renders markup
BAD
$myApi and Vuetify components are not available in an application instance of of my-component
If I copy the same files into the app and change my import, all works as expected. So, I now wonder if I'm missing something regarding sharing code via external modules.
I've tried these alternatives with the same issue:
use npm link to link the plugin module to the app
manually, use mklink (Windows sym link) to link plugin module to node_modules in the app folder
use a long relative path reference to the plugin module: import MyPlugin from "../../../my-plugin"
I've put this issue off for a while, but for anyone wondering, the issue is with using Single File Components and webpack not compiling those in external modules.
The 2 options I have are:
Don't use Single File Components. I.e.: Just use .js instead of .vue. I've seen some libs like Vuetify.js take this approach
Compile the .vue files in the library module and include them in the source such as ./dist folder.