How can I fully deploy my front end Vue app? - vue.js

My site uses Vue, Bootstrap, and Vuetify. It works locally. I deployed it on Netlify and Heroku with the same result. index.html runs, but not Vue. Bootstrap failed.
Here are 2 methods of deploying Bootstrap that work locally and their links. Method 1 fails.
Import locally.
Netlify
In main.js:
import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.min.css'
Import from a CDN.
Netlify Heroku
In index.html:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
Deployment steps:
For Heroku, I followed steps here with the below changes:
Commands I used in step 3:
npm run build
git add .
git commit -m "deploy"
I added a name to the app in step 4.
After deploying to Heroku, I had a dist folder directory. For Netlify, I dragged this to a box that said "Drag and drop your site folder here".
This is in package.json:
"scripts": {
"start": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
Michal LevĂ˝'s answer worked. I set publicPath when following a tutorial.
I commented it out in vue.config.js.
module.exports = {
"transpileDependencies": [
"vuetify"
],
// publicPath: process.env.NODE_ENV === 'production'
// ? '/skillportfolios/'
// : '/'
}
I got it working here in Netlify, but not Heroku. That's good enough.

Related

npm run dev mix doesn't work in laravel 9

I have a fresh laravel 9 project
I want to create an auth system with laravel command by using
composer require laravel/ui
and also
php artisan ui bootstrap --auth
after that I did
npm install
npm run dev
but rather that opening a mix development to generate css styles of auth pages it gave me this output in terminal
npm run dev image
and the page style is being like this
Page styles
I found the solution for this problem
the problem was in the package.json file
package.json was like this:
{
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"#popperjs/core": "^2.10.2",
"axios": "^0.25",
"bootstrap": "^5.1.3",
"laravel-mix": "^6.0.49",
"laravel-vite-plugin": "^0.4.0",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"sass": "^1.32.11",
"sass-loader": "^11.0.1",
"vite": "^2.9.11"
}
}
As you can see the dev in script was applied to vite,
"scripts": {
"dev": "vite",
"build": "vite build"
}
I just modified vite to mix and run
npm install again
and the problem was resolve and tyles of my login page generated successfully
Styles result
Update - ## Better Solution:
Installing Laravel/ui
composer require laravel/ui
Install Bootstrap Auth Scaffold
php artisan ui bootstrap --auth
In Vite.config file
import path by adding this at top:
import path from 'path';
after plugins add this:
resole: {
alias: {
'~bootstrap': path.resolve(__dirname, 'node_module/bootstrap'),
}
}
final result of vite config file will be like this:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import path from 'path';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/sass/app.scss',
'resources/js/app.js',
],
refresh: true,
}),
],
resole: {
alias: {
'~bootstrap': path.resolve(__dirname, 'node_module/bootstrap'),
}
}
});
From resources/js/app.js - add these lines
import '../sass/app.scss';
import * as boostrap from 'bootstrap'
Final Result of resources/js/app.js will be like this
import './bootstrap';
import '../sass/app.scss';
import * as boostrap from 'bootstrap'
Final Step is to change styles and script to #vite directive in resources/view/layouts/app.blade.php
change any css or js files from this type
<link href="{{asset('css/app.css')}}" rel="stylesheet" />
to #vite directive type
#vite(['resources/css/app.css', 'resources/css/app.css'])
Make sure you already have those files before trying to include it, otherwise vite will cause an error.

load styles in vue component package (npm)

I made vue component package and published it into npm.
It's work but the styles of the component are not loaded!
i made package with that command:
vue-cli-service build --target lib --name test-package ./src/index.js
and its part of my package.json:
"style": "./dist/test-package.css",
"main": "./dist/test-package.common.js",
and its styles of component:
<style scoped>
.my-bg {
backgorund: red;
}
</style>
Since you haven't provided a way to reproduce, it's impossible to know what exactly in your configuration causes this behavior. (By default CSS should be included, so you have some setting somewhere interfering).
This discussion contains a few possible fixes:
if your package.json contains: sideeffects: false, either remove it or change it to: sideEffects: ['*.css']
add css: { extract: false } to your vue.config.js's module.exports
Possibly related webpack/issues/6741:
Note: if you don't already have a vue.config.js, create it in root, with these contents:
module.exports = {
css: { extract: false }
}

Vuetify elements do not appear perfectly on netlify after deployment

My team and I developed a website using VueJS. In one of the pages, we used Vuetify elements such as vue-extension-panels and v-card. During development, we run using npm run dev and everything looks fine. I believe that all dependencies are installed correctly as it appeared fine during development.
Then, we deployed the web with Netlify. After deployment, Vuetify elements do not seem to appear correctly.
Below are the images that compare before and after deployment on Netlify:
Here is the packages.json:
So, it would be great if someone can explain why it is not showing properly or if someone knows netlify compatibility with Vuetify.
Thanks!
You are able to use any library with netlify. When you use $ vue add vuetify to add the dependency, everything should be fine. If you did install it otherwise, make sure to check the following things.
Vuetify is under dependencies in your package.json.
"dependencies": {
"core-js": "^3.4.3",
"vue": "^2.6.10",
"vuetify": "^2.1.0"
}
You correclty include it in your main.js
import Vue from 'vue'
import App from './App.vue'
import vuetify from './plugins/vuetify';
Vue.config.productionTip = false
new Vue({
vuetify,
render: h => h(App)
}).$mount('#app')
vuetify plugin (src/plugins/vuetify.js)
import Vue from 'vue';
import Vuetify from 'vuetify/lib';
Vue.use(Vuetify);
export default new Vuetify({});
You have a vue.config.js
module.exports = {
"transpileDependencies": [
"vuetify"
]
}

Vuetify / Offline icons

I have the following code for a menu and menu button. I am using Vue CLI 3 and Vuetify
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons">
...
<v-navigation-drawer fixed app v-model="drawer">
<MyMenu/>
</v-navigation-drawer>
<v-toolbar fixed app>
<v-toolbar-title class="headline text-uppercase">
<v-toolbar-side-icon #click.stop="drawer = !drawer"/>
</v-toolbar-title>
</v-toolbar>
The code works great when the computer is online. However when the computer is offline the menu button icon doesn't show up. Instead it is just replaced with the text 'MENU'. I have looked into installing (vue-material-design-icons, material-design-icons and material-design-icons-iconfont) via npm but have not had any luck getting the icon to display when the computer is offline. I'm not sure if there's a special way to wire it together that I'm unaware of. Can anyone provide insight as to how to solve this issue?
I've read a bunch of links such as https://github.com/vuetifyjs/cordova/issues/11 and How to host material icons offline? but I could not get them to work for me.
Vuetify address this in their documentation:
https://vuetifyjs.com/en/framework/icons#installing-fonts
Essentially:
npm install material-design-icons-iconfont -D
Then:
// main.js
import 'material-design-icons-iconfont/dist/material-design-icons.css' // Ensure you are using css-loader
import Vue from 'vue'
import Vuetify from 'vuetify'
Vue.use(Vuetify, {
iconfont: 'md'
})
ok, I finally got it working in VS Code.
npm install material-design-icons-iconfont
COPY the folder from the node_modules into you public/css folder (This is what I didn't do before)
Modify the material-design-icons.css file by changing the urls to start with
url('/css/material-design-icons-iconfont/dist/fonts/MaterialIcons-Regular
- in the index.html page of your project, add
<link rel="stylesheet" href="css/material-design-icons-iconfont/dist/material-design-icons.css">
my friends,
https://vuetifyjs.com/en/features/icon-fonts/#material-design-icons
first install mdi with npm install #mdi/font -D or yarn add #mdi/font -D
import in vuetify file import '#mdi/font/css/materialdesignicons.css' // Ensure you are using css-loader
and set in config export default new Vuetify({ icons: { iconfont: 'mdi', // default - only for display purposes }, })

React-Native, BleManager "Native Module cannot be null"

I wanted to try out the react-native-ble-plx library from Polidea
https://github.com/Polidea/react-native-ble-plx
So I created a new app in terminal and installed the library as explained by Polidea
create-react-native-app playground
npm install --save react-native-ble-plx
react-native link react-native-ble-plx
I then ran npm start and then i (for opening in iOS simulator)
and then I got the following error (in the terminal and in the simulator)
Native module cannot be null
node_modules/react-native/node_modules/fbjs/lib/invariant.js:44:24 in invariant
node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:31:16 in NativeEventEmitter
node_modules/react-native-ble-plx/src/BleManager.js:52:25 in BleManager
App.js:8:19 in App
node_modules/react-native/Libraries/Renderer/ReactNativeStack-dev.js:1679:33 in
node_modules/react-native/Libraries/Renderer/ReactNativeStack-dev.js:1610:15 in measureLifeCyclePerf
... 52 more stack frames from framework internals
Here is the code in App.js:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {BleManager} from 'react-native-ble-plx';
//importing BleManager without calling new BleManager() works
export default class App extends React.Component {
constructor(){
super();
this.manager = new BleManager();
}
//calling new BleManager() leads to error
render() {
return (
<View style={styles.container}>
<Text>nothing, just sucking errors</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Here is the file package.json
{
"name": "playground",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-native-scripts": "1.5.0",
"jest-expo": "^21.0.2",
"react-test-renderer": "16.0.0-alpha.12"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "^21.0.0",
"react": "16.0.0-alpha.12",
"react-native": "^0.48.4",
"react-native-ble-plx": "^0.6.3"
}
}
I already looked for help and tried
npm -rm rf node_modules
npm install
but it didn't help.
Here is my system information:
macOS High Sierra
iMac (27-inch, Mid 2010)
Processor 2.8 GHz Intel Core i5
Memory 16 GB 1333 MHz DDR3
I also got the same error when opening the app in my iPhone(6s, 10.3.1) (after scanning QR code in terminal from npm start)
Other apps without the react-native-ble-plx library work normally.
Looking forward receiving some help.
Thanks in advance.
Frank
You have used create-react-native-app to create your React Native project. So you can not use react-native-ble-plx library with this project. Because to access Bluetooth hardware, react-native-ble-plx package has some native code written in android and ios seperately.
If you want to build your app, you'll need to eject from create-react-native-app and use Xcode and Android Studio.
Use the below command:--
npm install -g react-native-cli
npm run eject
react-native link react-native-ble-plx
1st command is to install react-native-cli globally
2nd command is to convert your project from Expo project to regular React Native project
3rd command is to link react-native-ble-plx. Because most probably your previous link was failed.
What I did was (after completely removing ble-plx by discarding git changes before I started)
navigating to /node_modules/react-native-ble-plx/ios/BleClient.xcodeproj and
I pulled that into the Libraries folder in the project navigator
Then I went to my target -> build phases -> link binary with libraries and added libBleClient.a