Where are your css and js files for the normal template located? and do you use asset() function?
Incorporating summernote with laravel
I got summernote from summernote/summernote github page but have no idea which directories I should use and where in laravel I should put them. I also have no idea how to use webpack to get it working. Currently, I'm not using app.js or app.css because I never figured out how to work them.
@mancir I just use asset and I have all my js and css files in a js and css folders which are located in the public folder. I'm not good with javascript and never had used anything like webpack or vite before. Took a break from web development some years ago and now I come back and even javascript needs to be compiled like a C language. Why does 'moving forward' means having to complicate things?
What have you tried?
@jaseofspades88 I don't know what to do from the start so at the moment I'm asking for help and looking through online tutorials on how to use webpack and vite (I'm not sure if I even have to use any of these to make summernote work here).
If you read the documentation on the summernote github page, @Bogey it tells you how to include it with a CDN and how to instantiate it with jQuery. If you're not really interested in learning how to use webpack or vite, then you can use the CDN method.
I would however advise you get your head around vite as it's a really effective way of managing your dependencies.
@jaseofspades88 I'm trying to wrap my head around vite, and in the discussion on summernote github, they say the cdn is not up to date and that we should try using the repository over the cdn. I'm trying to learn how to use vite, which is why I came here asking for help. Telling me to learn vite in response is not helpful at all.
There are plenty videos here at Laracasts, that talk about Vite and spoon-feed it to you. Perhaps watch some of those, @Bogey
I installed a fresh copy of laravel and set up breeze on it and trying to figure out how vite works. Struggling with it... why the heck did they make javascript a compiled language now?
I moved files into and around the resources/js folder and edited the import calls in tons of javascript files until vite stopped giving me the unresolveable errors and now I'm getting a blank page. My generated app.js looks like:
import "/resources/js/bootstrap.js";
import "/resources/js/jquery.3.7.1.min.js";
import "/resources/js/bootstrap.bundle.min.js";
import "/resources/js/summernote-bs5.js?t=1704228795008";
import Alpine from "/node_modules/.vite/deps/alpinejs.js?v=aae8739a";
window.Alpine = Alpine;
Alpine.start();
//# sourceMappingURL=data:application/ ... ... clipped
The import "/resources/js/jquery.3.7.1.min.js"; is supposed to be import "/resources/js/jquery.js"; at least that's how the file is named in that folder. I restart the server but that doesn't recompile... clearing the cache doesn't help.
And with app.css I'm having problems as well... I removed all those @tailwind imports and importing my bootstrap5.css but nothing is changed. Looking at the source of the generated app.css I'm still getting those @tailwind imports. Removing tailwind.config.js from root directory doesn't yield any results either.
Importing all that in app.js, the console says, Uncaught ReferenceError: $ is not defined... jquery isn't even present...
I just deleted the project and completely reinstalled it and when running npm run dev (after running npm cache clean --force) the app.js still shows the generated code from my last project!!! This thing is trying to make me bald...
Got to the point where the summernote textarea is displayed (doesn't function) and some unformatted buttons which don't really function. I also get the following errors in console
jQuery.Deferred exception: $node.attr(...).tooltip is not a function ui/button/<@http://[::1]:5173/resources/summernote/summernote-bs5.js:191:14
render@http://[::1]:5173/resources/summernote/js/renderer.js:40:12
addToolbarButtons/<@http://[::1]:5173/resources/summernote/js/module/Buttons.js:287:10
build@http://[::1]:5173/resources/summernote/js/module/Buttons.js:814:53
invoke@http://[::1]:5173/resources/summernote/js/Context.js:238:33
initialize@http://[::1]:5173/resources/summernote/js/module/Toolbar.js:31:20
initializeModule@http://[::1]:5173/resources/summernote/js/Context.js:156:14
_initialize/<@http://[::1]:5173/resources/summernote/js/Context.js:79:12
_initialize@http://[::1]:5173/resources/summernote/js/Context.js:78:31
initialize@http://[::1]:5173/resources/summernote/js/Context.js:31:10
Context@http://[::1]:5173/resources/summernote/js/Context.js:23:10
summernote/<@http://[::1]:5173/resources/summernote/js/summernote.js:28:25
each@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:218:28
each@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:100:25
summernote@http://[::1]:5173/resources/summernote/js/summernote.js:25:10
@http://[::1]:5173/resources/js/app.js:12:22
mightThrow@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:2009:40
node_modules/jquery/dist/jquery.js/</Deferred/then/resolve/</process<@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:2047:23
setTimeout handler*node_modules/jquery/dist/jquery.js/</Deferred/then/resolve/<@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:2072:29
fire@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:1805:37
fireWith@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:1903:17
fire@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:1910:18
fire@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:1805:37
fireWith@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:1903:17
ready@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:2205:21
setTimeout handler*node_modules/jquery/dist/jquery.js/<@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:2215:17
node_modules/jquery/dist/jquery.js/<@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:11:44
node_modules/jquery/dist/jquery.js@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:20:7
__require@http://[::1]:5173/node_modules/.vite/deps/chunk-P2LSHJDD.js?v=9fe59374:4:50
@http://[::1]:5173/node_modules/.vite/deps/jquery.js?v=cf03748e:6354:16
and
Uncaught TypeError: $node.attr(...).tooltip is not a function
My app.js looks like
import './bootstrap';
import '../summernote/summernote-bs5';
import $ from 'jquery';
window.$ = window.jQuery = $;
$(document).ready(function () {
$('.summernote').summernote();
});
and my vite config
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
resolve: {
alias: {
'jquery': path.resolve(__dirname, '/resources/js/jquery.3.7.1.min.js'),
},
},
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
],
refresh: true,
}),
],
});
package.json
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.2",
"alpinejs": "^3.4.2",
"autoprefixer": "^10.4.2",
"axios": "^1.6.1",
"laravel-vite-plugin": "^1.0.0",
"postcss": "^8.4.31",
"sass": "^1.69.7",
"tailwindcss": "^3.1.0",
"vite": "^5.0.0"
},
"dependencies": {
"jquery": "^3.6.0",
"summernote": "^0.8.15"
}
}
I've being messing around with different version of jquery, but it doesn't seem to matter which version I try.
Ok, new question. If I use vite, I can't have javascript that is inline? All of my javascript has to be in app.js? What if there are portions of the javascript that are dynamic?
A real good video to help you 'get your head round' vite, @Bogey... https://laracasts.com/series/andres-larabits/episodes/31
As for 'inline javascript' you can still use such techniques for writing your javascript, @Bogey but using things like Vite will help you bundle any and all of your javascript together, it usually handles minifying your assets too so that you're not serving as large files when you eventually go to production.
Consider looking at how you can export any of your aforementioned inline javascript out to modules where it can be properly organised and use things like export default where appropriate.
@jaseofspades88 thank you. Seen that video but it's outdated and barely covers the bare minimum. Doesn't explain that it scopes all of the javascript out of the blade scope and disables the usage of javascript in blade files
@jaseofspades88 i dont know javascript, which is why i need a good tutorial to figure out how to hack vite to work for my use case.
Please or to participate in this conversation.