I am starting a new Laravel project with v5.2 and I would like to use Zurb Foundation v6.2.
I've seen that Zurb Foundation can be installed through composer and since I've installed Laravel through composer, I thought it as a good idea.
I did it, Foundation is in the vendor (vendor/zurb/foundation) folder.
It has also been added to the composer.json:
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"zurb/foundation": "^6.1"
},
But now, how can I use it? Where should I create my css file(s)? In the resources/assets/sass folder where Laravel already provides a scss file (app.scss)? If so, how can I link it to Zurb Foundation?
Thanks a lot for your help.
I think Laravel Elixir is more suitable for this purpose.
From the guide:
Installing Node
Before triggering Elixir, you must first ensure that Node.js is installed on your machine.
node -v
By default, Laravel Homestead includes everything you need; however, if you aren't using Vagrant, then you can easily install Node by visiting their download page. Don't worry, it's quick and easy!
Gulp
Next, you'll want to pull in Gulp as a global NPM package like so:
npm install --global gulp
Laravel Elixir
The only remaining step is to install Elixir! With a new install of Laravel, you'll find a package.json file in the root. Think of this like your composer.json file, except it defines Node dependencies instead of PHP. You may install the dependencies it references by running:
npm install
Then to install Foundation 6 for Sites it's recommended to use Bower, (another) package manager, but specifically for managing frontend facing libraries like Foundation and jQuery.
You can have a look at Zurb's example template for better understanding.
npm install --global bower
Create a file named bower.json:
{
"name": "my-site",
"dependencies": {
"foundation-sites": "~6.1.2",
"motion-ui": "~1.1.0",
"foundation-sites": "~6.2.0",
"motion-ui": "~1.2.2"
},
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"private": true
}
Then run bower install.
In app.scss, import Foundation:
#import 'foundation';
#include foundation-everything;
Then in gulpfile.js, compile it to CSS:
mix.sass('app.scss', 'public/css/app.css', {
includePaths: [
'bower_components/foundation-sites/scss/'
]
});
Finally to compile, run:
gulp
I think npm way is better suited for front-end stuffs. Take a look at this:
http://somethingnewtutorial.blogspot.com/2017/07/using-foundation-6-with-laravel-5.html
If you are using earlier version, its just using gulp instead of laravel-mix.
Related
What is the workflow of installing and using any js/css library using npm in laravel 8. What steps should I follow?
For an example let's say I want to install fontawesome using npm and use it in my laravel project. What I know is, once I run the npm install --save #fortawesome/fontawesome-free command it creates a folder for that inside node_modules.
I don't know what should I do after npm install --save #fortawesome/fontawesome-free.
How can I get to know what to do inside resources/css/app.css and webpack.mix.js and what next for any js or css library?
You can use laravel mix, based on my experience the general step to use any css / js package from npm to laravel mix is :
npm install.
import the css needed by the library to resources/sass/app.scss
require js script needed by the library to resource/js/bootstrap.js
npm run development or npm run production to rebuild the app.css and bootstrap.js.
For fontawesome you can read further in this tutorial:
https://dev.to/dendihandian/adding-font-awesome-to-laravel-the-laravel-mix-way-4ndj
I have an existing ASP.net application in Visual Studio. Until recently I only used JavaScript. Now I want use Typescript. Installing and transpiling works great. However, I got stuck when I wanted to import modules.
My idea was to use npm for loading modules, e.g. I added to package.json:
"devDependencies": {
"typestyle": "^1.7.1",
}
which I want to import in my .ts file via:
import { style } from 'typestyle';
The problem: npm downloads to folder node_modules which does not belong to my project (but it is inside my project folder); the import statement does not find the required files.
Currently I am using requirejs to enable import statements as explained here. My tsconfig.json looks like this:
{
"compilerOptions": {
"noImplicitAny": true,
"noEmitOnError": true,
"sourceMap": true,
"target": "es5",
"module": "amd",
"moduleResolution": "node"
}
}
I can download typestyle.js manually, put it in my project folder, and configure the requirejs configuration file main.js so that it finds it. But then I am not using npm.
How can I import modules that I loaded with npm? I'd like to use requirejs. I do not want Angular or React. If possible I also want to avoid other things which make my project unnecessarily complicated (Mocha, node.js, knockout, Webpack, Gulp, Browserify, ...)
EDIT
Okay, after reading NPM vs. Bower vs. Browserify vs. Gulp vs. Grunt vs. Webpack I guess I do need a module bundler like Webpack or Browserify. But maybe there is some tool integrated in VS2017 which I could use?
EDIT2
And after reading How it feels to learn JavaScript in 2016 (note: this is 2018) I understand that it might be too much to ask for a simple solution...
Finally I found a solution which suits my needs. Since it is very lengthy I'll just post the link (project source code)
http://codingsight.com/using-npm-webpack-and-typescript-to-create-simple-aspnet-core-web-app/
Only drawback so far: It uses Webpack instead of requirejs. Webpack is a module packer. All .js files/modules are combined into one huge .js. No lazy loading by default.
Is it possible to use Bourbon and it's additional components without needing to have Ruby installed? We'd like to experiment on a small project, but it's a pain to get dependencies approved by the desktop engineering folks.
I've noticed that there are Bower packages for all but Bitters. Can I just grab the scss files from GitHub and wire things up manually?
Seems the devs don't want to have bitters on bower: https://github.com/thoughtbot/bitters/issues/22.
That said, you can get bitters with bower if you use a zipball from git as a version (e.g. https://github.com/thoughtbot/bitters/archive/master.zip).
If you want more control on how to bring those files in your project, gulp-bower-normalize can help — an example bower.json file:
{
"name": "project-x",
"dependencies": {
"bitters": "https://github.com/thoughtbot/bitters/archive/master.zip",
},
"overrides": {
"bitters": {
"main": [
"app/assets/stylesheets/*.scss"
],
"normalize": {
"css/base": "**/*.scss"
}
}
}
}
Had this same question recently as I'm using Bourbon/Neat in a static site project. I've found that the 'bourbon' and 'neat' commands do nothing more that replicate the hierarchy of library files into your project directory. At that point you can use the libraries with any workflow which is able to preprocess sass/scss files.
In my case I'm using them successfully with the Python WebAssets library from within Pelican, you might be able to find another sass preprocessor that fits into your setup.
If you can get node installed on your dev machine check out Yeoman. It uses Grunt and Bower to generate a web app that uses Sass. Then you can install Bourbon and Neat using Bower. It does a lot of the heavy lifting for you.
I'm new to composer and Yii2. Already installed yii2 on Windows and now I need to install new bower dependency called bower-asset/angular-material. Added "bower-asset/angular-material": "0.4.2" to composer.json require block and run composer update bower-asset/angular-material. It takes too long time (about 1 hour). Somehow composer read all patches of angular
Reading bower.json of bower-asset/angular (v1.3.0-patch2531)
Reading bower.json of bower-asset/angular (v1.3.0-patch2530)
Reading bower.json of bower-asset/angular (v1.3.0-patch2529)
...
Why it takes too long time? What I need to do?
fxp/composer-asset-plugin >= v1.3:
To skip reading -patch packages, you need just added to composer.json of your project follow config of fxp/composer-asset-plugin:
"config": {
"fxp-asset": {
"pattern-skip-version": "(-build|-patch)"
}
}
Note: also this meaning the -build packages also will be skipped.
fxp/composer-asset-plugin < v1.3:
If you are using fxp/composer-asset-plugin older than version 1.3, you can use follow config:
"extra": {
"asset-pattern-skip-version": "(-build|-patch)"
},
That should work.
Make sure you are running the latest version of Bower. I am currently running v1.2.6 and null works to fetch the latest dependency.
$ bower -v
If you have installed bower globally via npm, then you can update it this way:
$ npm update bower -g
Note: you may need to run that as sudo depending on your file permissions.
Hope this helps.
How would I go about installing 2 versions of jQuery using bower? I want to have v2.0 as well as 1.9.1 for browser support fallback
The issue I'm having is that if you run bower install jquery#1.9.1 jquery#2.0.0 the first version gets overwritten by the second because they are the same component
According to the bower docs
Bower offers several ways to install packages:
# Using the dependencies listed in the current directory's bower.json
bower install
# Using a local or remote package
bower install <package>
# Using a specific version of a package
bower install <package>#<version>
# Using a different name and a specific version of a package
bower install <name>=<package>#<version>
You can install two different versions of jQuery like so:
bower install jquery-legacy=jquery#1.10 jquery-modern=jquery#2
Or, if you prefer to set that up in a bower.json
"dependencies": {
"jquery-legacy": "jquery#1.10",
"jquery-modern": "jquery#2"
}
In the dependencies part of your bower.json you can have something like this:
"dependencies": {
"jquery": "2.0.0",
"jquery-1.9.1": "http://code.jquery.com/jquery-1.9.1.js"
}
One shouldn't normally have to do this, but sometimes you have to maintain / migrate an existing website that (for whatever reason) uses different versions of jquery in different pages!
From the command line, if you just want the latest 1.x and 2.x versions, you can loosen the constraints in the answer above.
So:
bower install jquery-legacy=jquery#1.10 jquery-modern=jquery#2
would become:
bower install jquery-legacy=jquery#^1 jquery-modern=jquery
bower.json:
This is how i did it...
"dependencies": {
...
"jquery": "2.0.0",
"jquery-old": "1.9.1"
...
}
Second version, can be any version, old or new. You just have to add a different key. Like jquery-old
Install
bower install --save jquery-old
Use
Now you can use either one of the jquery version:
<script type="text/javascript" src="path/to/bower/directory/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="path/to/bower/directory/jquery-old/dist/jquery.min.js"></script>
Bonus
"dependencies": {
...
"jquery": "2.0.0",
"jquery-old": "1.9.1"
"jquery-latest": "^3.3.1"
...
}