Laravel Mix Does Not Pull In CSS
I have everything working nicely on my development server, however when I implement the the system onto my remote server at DigitalOcean, I am not getting my proprietary css.
My css is pulled in like this:
<link href="{{ asset('/css/app.css') }}" type="text/css" rel="stylesheet">
<link href="{{ asset('/css/default.css') }}" type="text/css" rel="stylesheet">
My mix will compile, but does not bring in the default/css
Any suggestions?
Did you validate that you actually had a public/css/default.css file? If you have one, open your devtools and check your "Sources" tab. Open the css folder and click on default.css, do you see all your CSS classes (use Cmd + F to search)? Else, what do you see?
@vincej so which one is missing the default.css or the app.css?
post your mix.js
@lemmon default is missing. I have no idea why app.css is empty, but that seems to be common amongst what I have seen and read. Thanks.
@lemmon Sorry, I was on my cell phone last post, could not get to my mix.js
Also apologies for what may seem like dumb questions, I am a total newb with Vue etc having just some over from JQuery. Let me guess .... my default.css is not included here and that is why it is not working???
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
@vincej what is in the resources/sass/app.scss file post that file
this file is the entry point for any includes and or css/sass so whatever this file points to should be in public/css/app.css.
In my local machine where the development was done I have:
// Fonts
@import url('https://fonts.googleapis.com/css?family=Nunito');
// Variables
@import 'variables';
// Bootstrap
@import '~bootstrap/scss/bootstrap';
In the remote DigitalOcean server I have nothing /empty
Note: I do not use scss I just write raw css.
Also, note - in my dev machine my default.css is pulled in. I guess my remote machine mix is not configured properly. I have a thought that my error lies in that I have placed my default.css inside the public folder since I have never used Mix before. So, I am thinking that with Mix in place I now need to move my default.css into resources / css / default.css, and run dev???
resources/sass/app.scss
// Bootstrap
@import '~bootstrap-sass/assets/stylesheets/bootstrap';
//or Tailwind
@tailwind base;
@tailwind components;
@tailwind utilities;
// or some include
@import 'components/dropdown';
// etc
.border-error {
@apply
border-red-500;
}
// or some css
@import url("../css/style.css");
it is now looking in:
resources/sass/app.scss
and will compile whatever you have in there to public/css/app.css
based on your mix file and your app.scss file you posted that includes bootstrap
Excellent.
I am thinking that perhaps I should modify the webpack.mix.js file to look like this - what do you think?
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.css('resources/css/default.css','public/css');
here is a good free tutorial about mix,
https://laracasts.com/series/laravel-6-from-scratch/episodes/17
or import it in your resources/sass/app.scss like:
// or some css
@import url("../css/default.css");
if default.css is located
'resources/css/default.css'
Ok, thanks I'll watch that - importing default.css into app.scss did not work, when I do a npm run dev I got. Note I do not see app.scss. Modifying my mix file does not work either:
DONE Compiled successfully in 9933ms 12:26:24
Asset Size Chunks Chunk Names
/css/app.css 178 KiB /js/app [emitted] /js/app
/js/app.js 1.4 MiB /js/app [emitted] /js/app
I know you guys must be fed up with this, but I am now desperate, so please bear with me. I have read the Laravel docs, AND I watched two videos from Jeffrey Way on setting up Mix. The good news news is that my Mix will compile the following files: Javascript, Vue, Sass.
But it absolutely refuses to compile my default.css. Here is my webpack.mix.js file:
const mix = require('laravel-mix');
mix.js(['resources/js/app.js', 'resources/js/functions.js'], 'public/js')
/* .css(['resources/css/default.css', 'resources/css/app.css'], 'public/css')*/
.css('resources/css/app.css', 'public/css')
.css('resources/css/default.css','public/css');
.sass('resources/sass/app.sass','public/css');
as you can see I tried putting my default.css and my app.css in an array, but that made no difference. Indeed Jeffrey has them in separate files as well.
I have restarted my DigitalOcean server, I have updated NPM. The only thing I have not done is uninstalled Mix and reinstalled it, only because it appears to be working for the other files. I do have a strange file called app.css.map which is very ugly. I have no idea what it does.
If any of you can rack your brains as to why it will not do my default.css you will receive my everlasting gratitude ! :o)
Many Thanks !
What happens if you add a trailing / to 'public/css'?
Like this:
mix.js(['resources/js/app.js', 'resources/js/functions.js'], 'public/js')
.css('resources/css/default.css','public/css/');
.sass('resources/sass/app.sass','public/css/');
Notice the change, 'public/css/' from 'public/css'.
Anything?
Thanks for not giving up on me. Tried that, and it had no affect. I have another idea. The sass file is compiling. Is there a reliable utility to convert css to sass, or do I have to do it manually?
Found one - I hope it works!!
mix.js(['resources/js/app.js', 'resources/js/functions.js'], 'public/js')
.css('resources/css/default.css','public/css/');
.sass('resources/sass/app.sass','public/css/');
If your default.css is vanilla css your mix should be
mix.js(['resources/js/app.js', 'resources/js/functions.js'], 'public/js')
.styles('resources/css/default.css','public/css/');
.sass('resources/sass/app.sass','public/css/');
Thanks for that, but nope styles did not work. Bummer. So, far I have had the most success with converting the css into scss and compiling that. It is alsmost as if something in the config of webpack refuses to look at raw css
can you post your error with styles
Can you show your package.json as well as the structure of your resources directory?
There is no error as such, it just does compile.
"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 --disable-host-check --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.21.1",
"bootstrap": "^4.0.0",
"cross-env": "^7.0",
"jquery": "^3.2",
"laravel-mix": "^5.0.9",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"resolve-url-loader": "^3.1.0",
"sass": "^1.15.2",
"sass-loader": "^8.0.0",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"vue": "^2.6.12"
}
}
Resources:
css
js
lang
sass
views
@vincej Okay I think have a solution: In your resources/sass/app.scss file (make sure it's .scss and not .sass), put this:
@import "../css/default";
Your webpack.mix.js will looks like:
mix.js(['resources/js/app.js', 'resources/js/functions.js'], 'public/js')
.sass("resources/sass/app.scss", "public/css/");
This will combine both into a single css file, and then you bring in your main layout file
<link href="{{ asset('/css/app.css') }}" type="text/css" rel="stylesheet">
OR
Upgrade to laravel-mix version 6 and update your webpack.mix.js file to :
mix.js(["resources/js/app.js", "resources/js/functions.js"], "public/js/app.js").vue()
.sass("resources/sass/app.scss", "public/css")
.css("resources/css/default.css", "public/css");
If you upgrade to laravel-mix 6, you might need to get rid of --hide-modules in your npm script "npm run development" and "npm run production"
Thank you very much for all your efforts! I will update you tomorrow. Cheers
Use mix helper in your view instead of assets
Thanks for that - I will update you tomorrow. Cheers
@apex1 Bravo!!! You will the golden crown of victory! I tried your first option, and nothing much changed, in the sense that everything worked but there was no compilation going on. So, on to option two - upgrade. Well that required the upgrading a various dependencies including node. But in the end it was all worth it. I tried in production and it minified my default css excellently. However, I still have one error coming through on the console.
Uncaught TypeError: Vue.component is not a function
There is a "solution" to it on Laracasts, but I am suspicious of it.
Also I notice, that where it did minify the default.css and app.js nevertheless, functions.js were not minified. Curious.
I still have an entirely different problem around CORs policy, but I will create a separate question for that. I am astounded that this question has needed 264 active views in order to arrive at a a solution. In the end the solution was standing in pain site. I am indebted to you. Thanks is not enough. Best answer applied.
Ok Fixed Vue error with in app.js:
import Vue from 'vue'
window.Vue = Vue;
I saw this post come by when someone had a issue with webpack. He switched from Vite back to webpack because he has issues, yet the same happend to him as what the OP was telling.
After some testing i found out that he has a space in the path. (Full path on his disk) ex. C:/Users/His Name/project/src/resources/css/app.scss.
After he made a symlink: to C:/Users/HisName/ -> C:/Users/His Name. And CD to the alias, it worked.
Even though it's an old post, maybe this would help someone.
@LaraLove2412 Hi Ya! I am the OP, I am thinking of giving Vite another try. Thanks for your input!
Please or to participate in this conversation.