I'm completely new to laravel mix and npm in general so I'm at total loss here.
I'm using jquery plugins such as: https://github.com/noraesae/perfect-scrollbar
Now, I installed laravel mix since I needed laravel echo.
Got that working and running up, but since then the jquery plugins are not loading, all I'm getting is:
Uncaught TypeError: $(...).perfectScrollbar is not a function
I don't know, is this perhaps that the jquery is now loaded async and Mix overwrites the one which I have set up /div> way?
However, I noticed I could perhaps install this plugin via npm due to documentation via:
npm install perfect-scrollbar
I did that, it installed but how can I now possibly include it so that laravel mix loads it as well? I've spent the last 6 hours trying to find a way but I just can't understand how to do this. Any help would be greatly appreciated!
Ok... not sure I get where your problem is but here is a few things you can check...
First, mix will run webpack... wbpack.mix.js ... which will contain something like this if you did not change it:
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
Now, this will run webpack and compile your resources... in the case we are interested in here, app.js.
Did you include your library (perfect-scrollbar) in app.js as suggested in the perfect scrollbar doc?
var Ps = require('perfect-scrollbar');
You will also need to take care of the css for it as well.. by importing it in your app.scss ... if you are using sass as in the standard laravel install...
#import "node_modules/perfect-scrollbar/src/css/main.scss"
Rebuild and you should be good to go if you use Ps as the perfect-scrollbar object. You can also add it to the window instead... like window.Ps = require...
npm install just installs the package in your node_modules directory. Once there, you must import them into your compiled css and js application file.
Hope this helps.
Related
I'm creating a new content type for 2sxc content and I'm trying to include some styling.
am I correct in assuming I add any custom css to 'src > styles > _styles.css'
if so, how do I update the package?
sorry for the newbie question and TIA
Regards
Martyn C
So yes, it's all SASS based. You should simply run npm ci in the root to restore all npm packages which are used for sass. Webpack should then take care of the building and all that :)
I suggest you have a look an the package.json where everything should be explained.
I've created a Laravel project 5.7 and i've used a lot of vue and vuex in this one and when i finished the project I was surprised that it's not working at all neither in IE 11 nor MS Edge.
I searched the web and lots of people mentioned "babel" term which is totally new for me, I installed it in my project but it's not working because I couldn't configure it with Laravel Mix.
After trying and installing packages nothing worked for me.
Here's what I did:
npm install --save #babel/polyfill
require("#babel/polyfill") in the top off public/js/app.js file
in webpack.mix.js file I changed this
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
to this:
mix.babel('resources/js/app.js', 'public/js/app.js')
.sass('resources/sass/app.scss', 'public/css');
I ran npm run dev but it didn't work.
What I need, since I'm totally new to Laravel Mix and this "babel" thing, is a configuration guide to the whole process.
picture of edge console log
Make sure that all of your vue components which are rendered inside of blade are not self closing. E.g. <vue-comment /> instead use <vue-comment></vue-comment> this is an issue I had which I tracked down to that.
Hopefully this is all it is.
I'm using the Metronic theme and installed the packages with npm and now a bunch of what I need is in the node_modules folder.
How do I link to these in laravel mix?
Ive tried googling and reading the laravel mix documentation however kind of stuck on this.
The documentation seems to explain how to import (.js and .css) and copy assets (images etc..)
Working With JavaScript: You could amend the example to something like mix.js('node_modules/metronic/src/js/framework/components/general/menu.js', 'public/js');
Working With Stylesheets: Amend this example to something like mix.sass('node_modules/metronic/src/sass/framework/_config.scss', 'public/css');
Copying Files & Directories: Directly from the example mix.copy('node_modules/foo/bar.css', 'public/css/bar.css');
please note the node_modules/metronic/ path is my best guess
I am not new to Laravel but am new to JavaScript frameworks.
I want to use React in a laravel build but cannot find any information on how to do this.
I have Laravel 5.4. I know this comes pre-packed with Vue and Laravel Mix instead of Gulp.
I am following the tutorial here: https://blog.tighten.co/adding-react-components-to-a-laravel-app but this is not meant for 5.4. It mentions needing to update the gulpfile but, since Laravel 5.4 doesn't use Gulp, there isn't one!
Can someone please help with a small tutorial or a couple of steps that I need to replicate in order to get React working in 5.4?
I have Googled but can only find NPM links, which are less than useful!
Thanks to Joe for pointing out the part of the docs that I needed. There was a little more to it so will describe my steps below to help anyone else out.
Delete the node_modules folder. This isn't necessary for brand new builds but if you have followed any other tutorials and installed things you don't need, this will save a few headaches. If you don't have a node_modules folder, ignore this step.
Please note that the above step will remove anything you have installed using NPM.
Run npm install from your project root. This will install all NPM components used by Laravel.
Open webpack.mix.js and change:
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
to
mix.react('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
Run npm run dev to compile the Javascript from the lesson contained in the question above. Your React JS outputs should now be working.
(optional) Use npm run watch to compile on the fly.
I really hope this helps someone else out as much as it helped me!
According to the docs, React support is built in to Mix:
Mix can automatically install the Babel plug-ins necessary for React support. To get started, replace your mix.js() call with mix.react():
mix.react('resources/assets/js/app.jsx', 'public/js');
Behind the scenes, Mix will download and include the appropriate babel-preset-react Babel plug-in.
I'm not 100% sure whether or not this'll automatically include React in your output bundle - my guess would be no (in which case you'll have to use a normal mix.js() call to pull it in).
This problem is driving me mad, I have been researching and have read about the standalone and runtime version of Vue. As far as I can tell Laravel 5.4/homestead ships with the standalone version as default.
The Vue development tools in chrome show the example component so I think that part is working correctly, just cannot render the template.
I am relatively new to Vue and npm been stuck in the past with jQuery, firstly where in laravel can I check/set I want the stand alone version of Vue? If it is not that problem does any one have any ideas?
Thanks for help
VueJS supports two ways of building apps like you said.
Load all necessary scripts within your page via script tags (not combined .vue files).
Compile and bundle all your files with Gulp, Browserify, Webpack or other tools.
Can you explain what you did so far. I guess you don't compile everything down.
The comment by peaceman was the solution, I had multiple calls to elixir, I condensed down to one and it worked straight away. Thanks everyone for your help.