vue component library not working together with vuetify in nuxt js - vue.js

I created a single button vue library and built it via vue-cli-service build --target lib.
And this option works fine in nuxtjs, but when I include vuetify in my package and try to use it in nuxtjs, the app throws an error
In nuxtjs I include vuetify via #nuxtjs/vuetify
Please help because I don't understand what is the problem.
My package.json in library
{
"name": "uikit",
"version": "0.1.0",
"private": false,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build --target lib --name uikit src/index.js",
"lint": "vue-cli-service lint"
},
"module": "./dist/uikit.common.js",
"main": "./dist/uikit.umd.js",
"files": [
"./dist"
],
"dependencies": {
"core-js": "^3.8.3",
"vue": "^2.6.14",
"vuetify": "^2.6.0"
},
"devDependencies": {
"#babel/core": "^7.12.16",
"#babel/eslint-parser": "^7.12.16",
"#vue/cli-plugin-babel": "~5.0.0",
"#vue/cli-plugin-eslint": "~5.0.0",
"#vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"sass": "~1.32.0",
"sass-loader": "^10.0.0",
"vue-cli-plugin-vuetify": "~2.5.8",
"vue-template-compiler": "^2.6.14",
"vuetify-loader": "^1.7.0"
},
"peerDependencies": {
"vue": "^2.7.10",
"vuetify": "^2.6.10"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "#babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
With <button> in the library it works fine and even #click works
enter image description here
What do I see when I use v-btn in my library
enter image description here
As you can see, when using v-btn in my application, apart from an error in the console, vuetify does not work completely except for styles
In nuxt.config.js
set build
transpile: \['#nuxtjs/vuetify'\] or transpile: \['vuetify'\]
also plugins: \[new VuetifyLoaderPlugin()\] didn't help

Have you updated nuxt.config.js the way it says in the Vuetify documentation and the nuxtjs/vuetify plugin page?
// nuxt.config.js
{
buildModules: [
// Simple usage
'#nuxtjs/vuetify',
// With options
['#nuxtjs/vuetify', { /* module options */ }]
]
}

Related

Vue CLI project not reading vue.config.js

I am trying to create some aliases to make my package cleaner but my project is ignoring my vue.config.js file. I am using the Vue CLI with Vue v^2.6.11.
vue.config.js:
const path = require('path')
module.exports = {
configureWebpack: {
resolve: {
alias: {
'#vue-toggle-component': path.resolve(__dirname, 'src/components')
}
}
}
}
package.json:
{
"name": "vue-toggle-component",
"version": "0.1.1",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"node-sass": "^4.14.1",
"sass-loader": "^10.0.4",
"vue": "^2.6.11"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
],
"description": "## Project setup ``` yarn install ```",
"main": "babel.config.js",
"repository": "git+https://github.com/nehlis/vue-toggle-component.git",
"keywords": [
"Vue.js",
"Toggle",
"Component",
"Lightweight",
"Checkbox"
],
"author": "Niels Bosman",
"license": "ISC",
"bugs": {
"url": "https://github.com/nehlis/vue-toggle-component/issues"
},
"homepage": "https://github.com/nehlis/vue-toggle-component#readme"
}
When I look online for a solution every page says Vue should read the config file. But it does not, since I tried console logging there and it had no output. Anyone knows more about this?

Broken image in dist package of vue application with webpack

I have a vue application with single file components, and I'm using webpack. One of the components has an image that works fine locally when I run it with npm run serve, but when I build the application (using npm run build) and deploy it online, I just see the broken image icon.
The image is is referenced in this in the component:
<img id="sockPhoto" :src="require('../assets/a_sock.png').default" alt="a_sock">
but if I inspect the same element in the deployed version, I see this:
<img data-v-f9e5c994="" id="sockPhoto" alt="a_sock">
which doesn't even have a src attribute.
This is the relevant part of my package.json:
{
"name": "my-app ",
"version": "0.2.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test": "jest"
},
"dependencies": {
"bootstrap": "^4.5.0",
"bootstrap-vue": "^2.15.0",
"core-js": "^3.6.5",
"file-loader": "^6.0.0",
"jquery": "^3.5.1",
"jspdf": "^1.5.3",
"popper.js": "^1.16.1",
"portal-vue": "^2.1.7",
"printd": "^1.4.2",
"vue": "^2.6.10"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^4.3.1",
"#vue/cli-plugin-eslint": "^4.3.1",
"#vue/cli-service": "^4.4.1",
"#vue/test-utils": "^1.0.3",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.0.1",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"jest": "^26.0.1",
"vue-jest": "^3.0.5",
"vue-template-compiler": "^2.6.11",
"vue-test-utils": "^1.0.0-beta.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"browserslist": [
"> 1%",
"last 2 versions"
],
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
"^[^.]+.vue$": "vue-jest",
"^.+\\.js$": "babel-jest"
},
"transformIgnorePatterns": [
"/node_modules/"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
}
}
}
Also, this was working before my latest deployment, which contained some modifications, but nothing I can think of that should mess this up.
I am relatively new to vue and webpack so all help is much appreciated.
EDIT: I have already tried the basic <img id="sockPhoto" src="./../assets/36_37.png" alt="a_sock">, but that didn't even work locally. This answer provided me with the method above, using require(...).default which was working fine until this last deployment.

Custom NPM Package installing issue

I made a custom npm package which I'm trying to install in my Vue application. I tried to follow some tutorials and steps but I'm getting an error below:
This dependency was not found:
chatinterfaceui in ./src/main.js
To install it, you can run: npm install --save chatinterfaceui
My main.js file in my chatinterfaceui lib is:
import ChatUi from './ChatUi.vue'
export default {
install (Vue, options) {
if (!options || !options.store) {
throw new Error('Please initialise plugin.');
}
Vue.component('chat-ui', ChatUi);
}
}
The package.json file for the chatinterfaceui lib:
{
"name": "chatinterfaceui",
"version": "0.1.0",
"private": false,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"build-bundle": "vue-cli-service build --target lib --name chatinterfaceui ./src/ChatUi.vue",
"lint": "vue-cli-service lint"
},
"main": "./dist/chatinterfaceui.common.js",
"dependencies": {
"autolinker": "^3.14.1",
"core-js": "^3.6.4",
"emoji-js": "^3.5.0",
"escape-goat": "^3.0.0",
"msgdown": "^1.0.2",
"node-sass": "^4.14.1",
"sass-loader": "^8.0.2",
"vue": "^2.6.11"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.3.0",
"#vue/cli-plugin-eslint": "~4.3.0",
"#vue/cli-service": "~4.3.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {
"vue/no-unused-vars": "off"
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
My main.js file for the Vue application is:
import Vue from 'vue'
import App from './App.vue'
import ChatUi from 'chatinterfaceui'
Vue.use(ChatUi)
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')
My package.js is:
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.19.2",
"chatinterfaceui": "^0.1.0",
"core-js": "^3.6.4",
"dialogflow": "^1.2.0",
"uuid": "^8.0.0",
"vue": "^2.6.11",
"vue-beautiful-chat": "^2.3.1"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.3.0",
"#vue/cli-plugin-eslint": "~4.3.0",
"#vue/cli-service": "~4.3.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"node-sass": "^4.14.0",
"sass-loader": "^8.0.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
In my main Vue application in which I want to use my library, when I try to use the library, I'm getting the warning. I feel I'm doing something silly, but can't understand or find what.

Vue CLI 3 app not loading in IE with some npm packages

I have created a Vue app with vue-cli 3. It was working fine in all browsers until I installed a npm package "microsoft-cognitiveservices-speech-sdk". To my knowledge, I guess, this particular package is not getting transpiled by babel. Below is my babel.config.js and package.json
//babel.config.js
module.exports = {
presets: [
'#vue/app'
]
}
//package.json
{
"name": "vueApp",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.19.0",
"core-js": "^2.6.5",
"microsoft-cognitiveservices-speech-sdk": "^1.7.0",
"vue": "^2.6.10",
"vue-good-table": "^2.18.0",
"vue-i18n": "^8.14.0",
"vue-router": "^3.1.2",
"vue-uuid": "^1.1.1",
"vuex": "^3.1.1"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^3.10.0",
"#vue/cli-plugin-eslint": "^3.10.0",
"#vue/cli-service": "^3.10.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"http-proxy-middleware": "^0.20.0",
"less": "^3.10.2",
"less-loader": "^5.0.0",
"vue-template-compiler": "^2.6.10"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
Once I installed the package, my application is not loading in IE (version 11) browser. But works like a charm in Google Chrome.
Can anyone help me out to solve this problem? Thanks in advance!
After a huge research and tried out the suggestions in the web, I have fixed the issue. So apparently, you need to create a configuration file for the app to transpile your troubling packages.
Create a vue.config.js in your root directory and add a property transplieDependencies, an array to contain your troubled libraries for es5 conversion.
//vue.config.js
module.exports = {
transplieDependencies: [
"your trouble library name"
]
}
Once you implemented the above changes, restart your server to get it working in IE.

How to import my Variables SCSS into Webpack for global use. (Vue)

I want to use variables within my code, but the issue is that I cannot use variables in each component without importing the .scss file into each component.
Someone mentioned that using Webpack may help, and would allow me to use the variables project-wide without individual imports.
The problem is, I have never messed with Webpack before and am not even sure where to import the scss file.
In Vue, I have my files "bundled" into one file (which I believe is the package.json).
My package.json file looks like this -
{
"name": "freelance",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"vue": "^2.5.21",
"vue-router": "^3.0.1"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^3.3.0",
"#vue/cli-plugin-eslint": "^3.3.0",
"#vue/cli-service": "^3.3.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0",
"node-sass": "^4.9.0",
"sass-loader": "^7.0.1",
"vue-template-compiler": "^2.5.21"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
Obviously, I cannot see any webpack there, so imagine I would need to add it? (or maybe somewhere else?) maybe someone can help? where would I import my "variables.scss" file.)
As I imagine you are using vue cli. You can create a file in your project folder called vue.config.js. Inside of that file you can define the following to load a scss file for each component (where your file is located in /styles/variables.scss):
module.exports = {
css: {
loaderOptions: {
sass: {
data: '#import "#/styles/variables.scss";'
}
}
}
};
You can read more about the vue.config.js file here: https://cli.vuejs.org/config/#css-loaderoptions