Trying to use versioning and i get this error .
Unable to locate Mix file: /core/public/css/app.css. (View: C:\laragon\www\project\core\resources\views\master.blade.php)
My webpack.mix.js file
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js').extract(['vue']);
mix.sass('resources/sass/app.scss', 'public/css');
if (mix.inProduction()) {
mix.version();
}
header
<link href="{{ mix('/core/public/css/app.css', '/core/public') }}" rel="preload" as="style"
onload="this.onload=null;this.rel='stylesheet'">
<script src="{{ mix('/core/public/js/manifest.js'), '/core/public'}}"></script>
<script src="{{ mix('/core/public/js/vendor.js'), '/core/public' }}"></script>
<script src="{{ mix('/core/public/js/app.js'), '/core/public' }}"></script>
mix-manifest.json output
{
"/js/app.js": "/js/app.js?id=170c03d22dcc6f5e5936",
"/css/app.css": "/css/app.css?id=3306ee8f312fb58dd115",
"/js/manifest.js": "/js/manifest.js?id=41f053ba9a94d81b39f8",
"/js/vendor.js": "/js/vendor.js?id=cf78339b219ecdecb320"
}
File structure inside project is
core
└───public
│ │ mix-manifest.json
│ │
│ └───js
│ │ app.js
│ │ manifest.js
│ │ vendor.js
│ |
| css
| | app.css
| |
|
|
|
|'''
└───webpack.mix.js
|...
Pointing to the javascript file like that
<script src="{{ mix('/js/app.js') }}"></script>
gives me an error
The Mix manifest does not exist. (View: C:\laragon\www\project\core\resources\views\master.blade.php) (View: C:\laragon\www\project\core\resources\views\master.blade.php)
Trying raw URL instead gives me this error
<script src="/css/app.css"></script>
GET https://project.test/css/app.css net::ERR_ABORTED 404 (Not Found)
The above file is located inside /core/public/css folder and it does not point correct.
This made it work
<link href="{{ mix('css/app.css', 'core/public') }}" rel="preload" as="style"
onload="this.onload=null;this.rel='stylesheet'">
<script src="{{ mix('js/app.js', 'core/public') }}" defer></script>
To explain, the second parameter points to where the mix-manifest.json file exists.
Your problem is that you are adding the root folder to your mix path... Do not do that, it is relative to your root/public...
You should have it like this:
<link href="{{ mix('/css/app.css') }}" rel="preload" as="style" onload="this.onload=null;this.rel='stylesheet'">
<script src="{{ mix('/js/manifest.js') }}"></script>
<script src="{{ mix('/js/vendor.js') }}"></script>
<script src="{{ mix('/js/app.js') }}"></script>
Read more about it here
Related
I have a Laravel 8 app running on Jetstream with Inertia Js and VueJs 3.
When I run: npm run prod
I receive this error:
Exception
Unable to locate Mix file: /css/app.css. (View: /var/www/html/mysite/resources/views/app.blade.php)
http://subdomain.mysite.com/
After changing:
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
to
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
and:
<script src="{{ mix('js/app.js') }}" defer></script>
to
<script src="{{ asset('js/app.js') }}" defer></script>
It works well. But isn't this wrong? What is the advantage of using mix instead of asset?
I also tried using <link rel="stylesheet" href="{{ asset(mix('css/app.css')) }}"> but it's still not working. I receive the same error saying that mix is unable to locate the file: /css/app.css
This is a simple Laravel app, without any customizations.
I tried to run npm run prod with the hope that the page size will be smaller, but I see the same page size as for npm run watch or npm run dev (17Mb).
Any advice for reducing the page size for a VueJs Laravel app?
UPDATE
webpack.mix.js content:
mix.js('resources/js/app.js', 'public/js').vue()
.postCss('resources/css/app.css', 'public/css', [
require('postcss-import'),
tailwindcss('tailwind.config.js')
])
.webpackConfig(require('./webpack.config'));
if (mix.inProduction()) {
mix.version();
}
mix-manifest.json content:
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css"
}
Modify the following statements:
#vite(['resources/css/application.css', 'resources/js/application.js'])
For this:
Css: link rel="style sheet" href="{{ mix('css/app.css') }}"
JavasScript: src="{{ mix('js/app.js') }}" defer
In the app.blade.php and guest.blade files located in resources\views\layout
I'm building a web page using Hugo.
Here is my website header:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Website</title>
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0" /> -->
<meta name="referrer" content="no-referrer" />
<link rel="icon" href="/img/favicon.ico" type="image/x-icon" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.2/tiny-slider.css"
/>
<!-- tried this as per suggestion from Hugo forums
{{ $sassIncludes := (slice "node_modules" "assets/scss/vendor" "assets/scss/components") }}
{{ $target := "styles/main.css" }}
{{ if .Site.IsServer }}
{{ $cssOpts := (dict "targetPath" $target "enableSourceMap" true "includePaths" $sassIncludes ) }}
{{ $styles := resources.Get "/css/main.scss" | toCSS $cssOpts }}
<link rel="stylesheet" href="{{ $styles.Permalink }}" media="screen">
{{ else }}
{{ $cssOpts := (dict "targetPath" $target "includePaths" $sassIncludes ) }}
{{ $styles := resources.Get "/css/main.scss" | toCSS $cssOpts | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.Permalink }}" integrity="{{ $styles.Data.Integrity }}" media="screen">
{{ end }} -->
{{ $style := resources.Get "/css/main.scss" | resources.ToCSS | minify | fingerprint}}
<link rel="stylesheet" href="{{ $style.RelPermalink }}"/>
</head>
<body>
<header>
<div class="nav-bar">
<a class="top-logo" href="/">
<img src="/img/logo.svg" />
</a>
</header>
</body>
</html>
Here is main.scss:
#import 'reset';
#import 'commonStyles';
#import 'pricing';
#import 'docs';
#import 'header';
#import 'footer';
#import 'home';
header {
.nav-bar {
background-color: red;
}
}
config.toml:
baseURL = "http://example.org/"
languageCode = "en-us"
title = "Website"
assetDir = "static"
I'm running on macOS with hugo server command. I'm changing the background color in styles. Here is terminal output:
thatsme/../website-landing (master↑1|✚7…) % hugo server
Building sites … WARN 2020/05/18 12:27:34 found no layout file for "HTML" for kind "taxonomyTerm": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/05/18 12:27:34 found no layout file for "HTML" for kind "taxonomyTerm": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
| EN
-------------------+-----
Pages | 14
Paginator pages | 0
Non-page files | 0
Static files | 19
Processed images | 0
Aliases | 0
Sitemaps | 1
Cleaned | 0
Built in 17 ms
Watching for changes in /Users/thatsme/git/website-landing/{archetypes,content,data,layouts,static}
Watching for config changes in /Users/thatsme/git/website-landing/config.toml
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
Change of Static files detected, rebuilding site.
2020-05-18 12:27:42.202 +0200
Syncing css/main.scss to /
Styling changes apply only when I restart server. Html changes are getting applied properly.
The following command should do the trick:
hugo serve --noHTTPCache --ignoreCache --disableFastRender
I used these vue js files to build my form in Larval.
When I call these files in Larval I get a blank page.
The structure of my files is as follows:
And the contents of app.js file is as follow:
import Vue from "vue"
import App from "./components/App.vue"
import store from "./components/store"
import VeeValidate from "vee-validate"
Vue.use(VeeValidate);
import "./components/directives"
Vue.config.productionTip = false;
new Vue({
store,
render: h => h(App)
}).$mount("#app");
Of course, I get the below warning when I run nmp run watch's command.
WARNING in ./resources/js/app.js 5:8-19 "export 'default' (imported as
'VeeValidate') was not found in 'vee-validate' # multi
./resources/js/app.js ./resources/sass/app.scss
My question is: How to import external vue js files to laravel project?
First thing you need to include app.js to your blade file like this
<script src="{{asset('js/app.js')}}"></script>
after that if you want to use vue js components in you blade app you need to define them in your app.js like this:
Vue.component('home', require('path to your component').default);
and in your blade under div #idd add your tag <home></home>
use src="{{ mix('js/app.js') }}"
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" value="{{ csrf_token() }}" />
<title>VueJS CRUD Operations in Laravel</title>
<link href="{{ mix('css/app.css') }}" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="app">
</div>
<script src="{{ mix('js/app.js') }}" type="text/javascript"></script>
</body>
</html>
I want to compile only selected file based on usertype. I've different vue instance file in resource/js and I want to mix only one of them.Currently I'm doing this
#if(Auth::user())
<script defer src="{{ mix('js/app.js') }}">
#else
<script defer src="{{ mix('js/guestApp.js') }}">
#endif
But it takes path from public folder,instead of resources. How do I achieve it? Can I mix resources/js/app.js file from blade?
I've found the solution and it is to conditionally using of js file
#if(Auth::user())
<script src="{{ asset('js/app.js') }}" defer></script>
#else
<script src="{{ asset('js/guestApp.js') }}" defer></script>
#endif
And then using different Vue app for different user type-
"resources/js/Guest/app.js"
And in my webpack compiling all at once-
mix.js('resources/js/Guest/app.js', 'public/js/guestApp.js')
.js('resources/js/app.js', 'public/js/app.js')
.sass('resources/sass/app.scss', 'public/css');
Wondering how can I link with blade syntax to my jquery/javascript files?
<script src="../../public/js/jquery.min.js"></script>
<script src="../../public/js/bootstrap.js"></script>
This didn't work:
<link type="text/css" rel="stylesheet" href="{{ URL::to('js/jquery.min.js') }}">
<link type="text/css" rel="stylesheet" href="{{ URL::to('js/bootstrap.js') }}">
URL::to($param) directs to your root folder (/public) and adds the string folders. URL::to('js/bootstrap.js') directs to /public/js/bootstrap.js. this looks correct to me.
although you used a css linking tag for javascript. try using:
<script src="{{ URL::to('js/jquery.min.js') }}"></script>
<script src="{{ URL::to('js/bootstrap.js') }}"></script>
You should use the following:
<script src="{{ URL::asset('/js/jquery.min.js') }}"><script/>
<script src="{{ URL::asset('/js/bootstrap.js') }}"><script/>
This will always work. If you are creating a package in workbench this is also the way to go.
And if you want to publish your assets to public you will do:
php artisan asset:publish --bench="vendor/package"