I've downloaded Video.js using npm, but I'm having trouble getting it imported to use it on the front end. Here are the steps I've taken:
Installed Video.js with npm, and the /node_modules directory was created.
Added code to webpack.mix.js at the beginning of the file.
webpack.mix.js
const mix = require('laravel-mix');
const path = require('path');
mix.webpackConfig({
resolve: {
alias: {
'videojs': path.resolve(__dirname, 'node_modules/video.js/dist/video.min.js'),
}
}
});
Ran npm run dev successfully.
added below code to view play.blade.php:
play.blade.php
<script type="module">
import 'videojs';
videojs('my-player');
</script>
I get this error Uncaught TypeError: Failed to resolve module specifier "videojs". Relative references must start with either "/", "./", or "../".
Why is it searching for a path when I'm using an alias?
I've tried so many variations of getting the package to import and no success, been stuck for 2 days. How do I solve this? I want to use video.js in the view.
First, install the latest version of Video.js.
npm install --D video.js
In /resources/js/bootstrap.js add...
window._ = require('lodash');
require('video.js');
Compile your assets...
npm run prod
Add the following to your layout.
<script src="{{ asset('js/app.js') }}"></script>
For reference here's my package.json.
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"axios": "^0.21",
"laravel-mix": "^6.0.18",
"lodash": "^4.17.21",
"postcss": "^8.2.13",
"video.js": "^7.11.8"
}
}
And also webpack.mix.js.
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
//
]);
Then, in the player.
<video
id="my-video"
class="video-js"
controls
preload="auto"
width="640"
data-setup="{}">
<p class="vjs-no-js">
To view this video please enable JavaScript,
and consider upgrading to a web browser that
<a href="https://videojs.com/html5-video-support/" target="_blank">
supports HTML5 video
</a>
</p>
</video>
If you want to use the CSS. then include in /resources/css/app.css:
#import "~video.js/dist/video-js";
Related
I have followed the steps mentioned in this link for desktop notification in localhost https://pusher.com/tutorials/desktop-notifications-laravel/. and run the command in cli 'npm run dev'.
after running the project using command 'php artisan serve' in live link getting the error
app.js
require('./bootstrap');
Vue.component('home', require('./components/Home.vue'));
webpack.mix.js
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
//
]).vue();
bootstrap.js
window._ = require('lodash');
/**
* We'll load the axios HTTP library which allows us to easily issue requests
* to our Laravel back-end. This library automatically handles sending the
* CSRF token as a header based on the value of the "XSRF" token cookie.
*/
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
/**
* Echo exposes an expressive API for subscribing to channels and listening
* for events that are broadcast by Laravel. Echo and event broadcasting
* allows your team to easily build robust real-time web applications.
*/
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
forceTLS: true
});
welcome.blade.php
<!-- ./resources/views/welcome.blade.php -->
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>News Talk</title>
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<style>
.container {
padding-top: 100px;
}
</style>
<!-- Scripts -->
<script>
window.Laravel = {!! json_encode([
'csrfToken' => csrf_token(),
]) !!};
</script>
</head>
<body>
<div id="app">
<!-- home Vue component -->
<home></home>
</div>
<!-- Scripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.12/vue.js"></script>
<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>
when run the command 'npm run dev'
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"axios": "^0.21",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"vue-loader": "^15.9.7",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"laravel-echo": "^1.11.3",
"pusher-js": "^7.0.3",
"vue": "^2.6.12"
}
}
Please help me to solve this issue.
First remove node_modules folder and package-lock file by running rm -rf node_modules/ package-lock.json.
Remove vue dependencies vue, vue-loader and vue-template-compiler from package.json file.
Now run npm install.
Install vue and vue-loader by npm install vue vue-loader file-loader
It will install vue 2.6.13 and vue-loader 15.9.7 and file-loader 6.2.0 version package.
Install npm install vue-template-compiler --save
In app.js file
require('./bootstrap');
import Vue from 'vue';
Vue.component('home', require('./components/Home.vue'));
You don't need to add cdn link in blade file. It will automatically added using webpack
you have missing this window.Vue = require("vue"); in
app.js
window.Vue = require("vue");
require('./bootstrap');
Vue.component('home', require('./components/Home.vue'));
put this on your package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"axios": "^0.21",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"vue-loader": "^15.9.7",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"laravel-echo": "^1.11.3",
"pusher-js": "^7.0.3",
"vue": "^2.6.12"
}
}
then run npm run update && npm run dev
Laravel was installed and so was Vue:
composer require laravel/ui
php artisan ui vue
npm install && npm run dev`
However, Laravel cannot find the Vue instance that is created in app.js.
welcome.blade.php:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<script src="js/app.js"></script>
</head>
<div id="app">
<example-component></example-component>
</div>
<script>
</script>
</body>
</html>
The error that appears in the browser console showing that Laravel can't fine the Vue instance named #app:
[Vue warn]: Cannot find element: #app
Any help would be greatly appreciated:
app.js
require('./bootstrap');
window.Vue = require('vue');
Vue.component('example-component',require('./components/ExampleComponent.vue').default);
const app = new Vue({
el: '#app',
});
package.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.19",
"bootstrap": "^4.0.0",
"cross-env": "^7.0",
"jquery": "^3.2",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"resolve-url-loader": "^2.3.1",
"sass": "^1.20.1",
"sass-loader": "^8.0.0",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
}
}
The only way I was able to get Vue working on Laravel was to use this as the correct example:
https://github.com/connor11528/laravel-vue-spa-tailwindcss
I am using Laravel 5.8 which includes Vue JS in it by default and I want to use Vuetify. Here is what I have done
I have followed exactly what is written in the blog https://codersdiaries.com/laravel-vuetify/ and I am getting an error message in the console that [Vue warn]: Error in beforeCreate hook: "Error: Vuetify is not properly initialized
Here are my files
welcome.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<link href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons' rel="stylesheet">
<script src="{{ asset('js/app.js') }}" defer></script>
</head>
<body>
<v-app id="app">
<h1>Test Vuetify</h1>
</v-app>
</body>
</html>
app.js
window.Vue = require('vue');
import Vuetify from 'vuetify'
Vue.use(Vuetify)
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
const app = new Vue({
el: '#app',
});
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.19",
"cross-env": "^5.1",
"laravel-mix": "^4.0.7",
"lodash": "^4.17.13",
"resolve-url-loader": "^2.3.1",
"sass": "^1.15.2",
"sass-loader": "^7.1.0",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"vuetify": "^2.0.18"
}
}
You aren’t giving Vue an instance of Vuetify:
const vuetify = new Vuetify();
const app = new Vue({
el: '#app',
vuetify
});
I can't figure out how to include JavaScript packages in my Laravel project. I've been trying to install packages, and I can't figure out how it works. For example: Let's say I want to install Bootstrap Confirmation (http://bootstrap-confirmation.js.org/).
I install it from my project root folder.
$ npm install bootstrap-confirmation2
After that, the package.json file looks like the following.
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.18",
"bootstrap": "^4.0.0",
"cross-env": "^5.2.0",
"jquery": "^3.2",
"laravel-mix": "^4.0.7",
"lodash": "^4.17.5",
"popper.js": "^1.15.0",
"resolve-url-loader": "^2.3.1",
"sass": "^1.15.2",
"sass-loader": "^7.1.0",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"#types/bootbox": "^4.4.36",
"bootbox": "^5.1.2",
"bootstrap-confirmation2": "^4.1.0"
}
}
I then add the package to app.js.
require('bootstrap-confirmation2');
And my webpack.mix.js looks like this:
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
After that, I run this from my console:
npm run dev
If I try to use my Bootstrap confirmation package it doesn't work, no errors, nothing.
<button class="btn btn-default" data-toggle="confirmation">Confirmation</button>
I know the problem is not in the package but in the way I try to install packages and including them in my app.js file that is loaded once I open the app.
I checked the 'Network' tab in Chrome dev tools, checked that 'app.js' is loaded, searched the file and the package I installed and included is INSIDE the JS file and it still doesn't work.
Any help is appreciated.
In the terminal, run the following install.
npm install bootstrap-confirmation2
The package.json should now look something like the following. Dependencies are jQuery, Popper.js (for Bootstrap 4), and of course, Bootstrap 4.
"dependencies": {
"bootstrap": "^4.3.1",
"bootstrap-confirmation2": "^4.1.0",
"jquery": "^3.4.0",
"laravel-mix": "^4.0.15",
"popper.js": "^1.15.0"
webpack.mix.js
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
app.css
// Variables
#import 'variables';
// Bootstrap
#import '~bootstrap/scss/bootstrap';
app.js
try {
window.Popper = require('popper.js').default;
window.$ = window.jQuery = require('jquery');
require('bootstrap');
require('bootstrap-confirmation2');
} catch (e) {}
In your Blade template/layout:
<a class="btn btn-large btn-primary" data-toggle="confirmation" data-title="Open Google?"
href="https://google.com" target="_blank">Confirmation</a>
At the end of the file, after the closing body tag:
</body>
<script src="{{ mix('js/app.js') }}"></script>
In app.js...
$('[data-toggle=confirmation]').confirmation({
rootSelector: '[data-toggle=confirmation]',
// other options
});
At the terminal:
npm run prod
I hope that helped.
I am working with Nuxt.js on my Laravel project. I needed to combine both of them together since they come with a boilerplate when installing them into my project.
I was able to get almost everything working up to the point where I needed my welcome.blade.php to be able to read my index.vue component that was created inside of my resources/nuxt/pages folder.
Currently, the problem I am getting is that I have an "unexpected identifier on line 1 of my public/App.js" file where I import vue.
Import Vue from 'vue'
SO. How things get compiled is through my yarn run dev-nuxt that I modified in my package.json (simplified | only showing what I think I need to | i'd be happy to show more upon request)
{
"private": true,
"scripts": {
"dev-nuxt": "nuxt",
},
Prior to that I was running yarn run dev
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
which would look at webpack.mix.js. When running yarn run dev my terminal would return these errors:
Module not found: Error: Can't resolve '~/components/Logo.vue' in 'C:\Users\Owner\Documents\META+LAB\iSTART\resources\pages'
# ./resources/pages/index.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib??ref--4-0!./node_modules/vue-loader/lib??vue-loader-options!./resources/pages/index.vue?vue&type=script&lang=js&) 28:0-41 32:10-14
# ./resources/pages/index.vue?vue&type=script&lang=js&
# ./resources/pages/index.vue
# ./resources/js/app.js
# multi ./resources/js/app.js ./resources/assets/app.scss
So then I also realized that my webpack.mix.jshas no references to my nuxt.config.js (simplified | only showing what I think I need to | i'd be happy to show more upon request)
const pkg = require('./package')
const path = require('path');
module.exports = {
mode: 'spa',
/*
** srcDir points to where nuxt will be compiled by yarn nuxt-dev
*/
srcDir: 'resources/',
/*
** buildDir is where my nuxt code will be compiled to
*/
buildDir: 'public/js/',
** Nuxt.js modules
*/
modules: [,
// Doc: https://bootstrap-vue.js.org/docs/
'bootstrap-vue/nuxt',
'nuxt-babel'
],
which has a reference to my .babelrc which should be compiling my vue into my App.js (simplified | only showing what I think I need to | i'd be happy to show more upon request)
{
"env": {
"test": {
"presets": [
[
"#babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"#nuxt/babel-preset-app"
]
}
}
}
So I'm not sure why I am getting this error. Is it possible that I have either my nuxt.config.js or my .babelrc set up improperly?
This is how my welcome.blade.php looks:
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet" type="text/css">
</head>
<body>
<div id="app">
<index></index>
</div>
<script src="/js/App.js"></script>
</body>
</html>
When compiling nuxt through yarn run dev-nuxt as declared in my package.json above, I get a port that shows my index.vue component perfectly, however I do not have access to this component when running php artisan serve
I have a feeling that I did not configure something properly, or that I need to install more packages?
For reference here is my whole package.json
"devDependencies": {
"#vue/test-utils": "^1.0.0-beta.27",
"axios": "^0.18",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"jest": "^23.6.0",
"jquery": "^3.2",
"laravel-mix": "^4.0.7",
"lodash": "^4.17.5",
"nodemon": "^1.18.9",
"popper.js": "^1.12",
"resolve-url-loader": "^2.3.1",
"sass": "^1.15.2",
"sass-loader": "^7.1.0",
"vue": "^2.6.2",
"vue-jest": "^3.0.2"
},
"dependencies": {
"#babel/core": "^7.2.2",
"babel-loader": "^8.0.5",
"bootstrap": "^4.1.3",
"bootstrap-vue": "^2.0.0-rc.11",
"cross-env": "^5.2.0",
"node-sass": "^4.11.0",
"nuxt": "^2.4.0",
"vue-loader": "^15.6.2"
}
I think on the html level, you still need to initialize Vue on #app in a script tag ... cause I don't think Vue is initialized , basically :
let app = new Vue({el : "#app'});