I'm trying to add Materialize to this modified sage wordpress theme it is sage with bootstrap removed along with stylus and lostgrid added. [That link is repo without materialize that I'm attempting to add Materialize to.]
I've added these changes yet the materializecss and js don't seem to be available.
"dependencies": {
"materialize": "^0.97.7"
},
"overrides": {
"materialize": {
"main": [
"./css/materialize.css",
"./js/materialize.js"
]
}
}
You can see the commit here. [This is a repo with materialize added to the bower.json.]
What more has to be done to add a bower package to a sage theme or what am I doing wrong?
According to this page / comment the only step required is what I have done in bower.json.
I'm not seeing any Bower libraries added to your bower.json in the repo you linked to, so step 1 is to enter your theme dir and $ bower install materialize --save. Note that I performed this on a fresh install of Sage after I removed all Bower packages and overrides (I also commented all the #import directives in main.scss that come after the wiredep block to safely remove any remnants of Bootstrap's SCSS variables). If you decide to skip to the end of my answer and just use my bower.json file as your own then you'll just need to enter your theme dir and run $ bower install.
After installing Materialize via Bower you should be able to run gulp and see evidence of Materialize, but there are a few issues we need to resolve:
The main property of the Materialize project points to a CSS file and a minified JS file, both of these are not ideal and we will override them.
That first issue above also means when you load your site after running gulp you'll see console 404s because we need to override the fonts too.
This is the final bower.json file I ended up with:
{
"name": "sage",
"homepage": "https://roots.io/sage/",
"authors": [
"Ben Word <ben#benword.com>"
],
"license": "MIT",
"private": true,
"dependencies": {
"materialize": "^0.97.7"
},
"overrides": {
"materialize": {
"main": [
"./dist/js/materialize.js",
"./sass/materialize.scss",
"./fonts/**/*"
]
}
}
}
You will also need to add this to your main.scss file before the wiredep block:
$roboto-font-path: "../fonts/";
The overrides can be improved to use just the individual SCSS components you need instead of all of them. The same goes for the JS source (although the JS files definitely need to be included in a specific order, there are a lot of them and I haven't seen a list anywhere of how they need to be ordered).
EDIT
If you want to include the JS files individually then I've figured out the order, just beware of dependencies if you remove anything and test thoroughly.
{
"name": "sage",
"homepage": "https://roots.io/sage/",
"authors": [
"Ben Word <ben#benword.com>"
],
"license": "MIT",
"private": true,
"dependencies": {
"materialize": "^0.97.7"
},
"overrides": {
"materialize": {
"main": [
"./js/initial.js",
"./js/jquery.easing.1.3.js",
"./js/animation.js",
"./js/velocity.min.js",
"./js/hammer.min.js",
"./js/jquery.hammer.js",
"./js/global.js",
"./js/collapsible.js",
"./js/dropdown.js",
"./js/leanModal.js",
"./js/materialbox.js",
"./js/parallax.js",
"./js/tabs.js",
"./js/tooltip.js",
"./js/waves.js",
"./js/toasts.js",
"./js/sideNav.js",
"./js/scrollspy.js",
"./js/forms.js",
"./js/slider.js",
"./js/cards.js",
"./js/chips.js",
"./js/pushpin.js",
"./js/buttons.js",
"./js/transitions.js",
"./js/scrollFire.js",
"./js/date_picker/picker.js",
"./js/date_picker/picker.date.js",
"./js/character_counter.js",
"./js/carousel.js",
"./sass/materialize.scss",
"./fonts/**/*"
]
}
}
}
Related
I have numerous Vue SPAs in a monorepo that all share a common set of global styles, each SPA and the styles are their own package.json workspace. I'm trying to replace one of them with Nuxt.
The global styles are .scss files, they import Vue bootstrap and have some custom variables and classes.
As such, I did a fresh install of Nuxt and then ran:
yarn add -D sass sass-loader#10 fibers
I know I can get global styles like so:
//in nuxt.config.js:
css: [resolve(__dirname+'/../common/styles/index.scss')
Really I thought that should/would be it, and I see it does get injected into the page. However, the class names are hashed, so it doesn't apply to my components.
Instead of this (fake css to test if it goes in the page):
.test{
text-align: test;
top: test;
}
I get this:
.olAmdkaWN_JnK1npjbKiI {
text-align: test;
top: test;
}
How can I stop the global styles from being hashed like this, especially when I may be importing components from the other SPAs/common and their classnames aren't being hashed in the HTML? Only the injected global styles are getting hashed like this.
I've tried various attempts at setting the localIdentName such as:
//in nuxt.config.js
build: {
extend(config) {
config.module.rules.push({
test: /\.scss$/,
use: [{
loader: 'css-loader',
options: {
modules: false
/*
or sometimes I'll try something like:
modules:{
localIdentName: '[local]'
}
*/
}
},
{
loader: 'sass-loader'
}
]
})
},
I've also set:
cssModules: {
localIdentName: '[local]'
},
Again in the nuxt.config.js. But nothing works and furthermore I think I must have a conceptual error about how global styles are meant to work, as I feel like I'm fighting the framework rather than working with it.
My nuxt, webpack and sass-loader verisons are as follows:
nuxt#2.15.4
webpack#4.46.0
sass-loader#10.1.1 (It was at 7.1.x but the console suggested upgrading it - didn't make a difference in terms of solving this)
package.json:
"dependencies": {
"core-js": "^3.9.1",
"common": "1.0.0", (local dependency)
"nuxt": "^2.15.3"
},
"devDependencies": {
"fibers": "^5.0.0",
"sass": "^1.32.11",
"sass-loader": "10"
}
Turns out all I needed was this (the key was to put it in loaders within build):
//in nuxt.config.js
build: {
loaders: {
cssModules: {
localIdentName: '[local]'
},
},
}
Please note this only works if you properly install your dependencies and heed build warnings in regards to css-loader and sass-loader. I tried downgrading sass-loader and this didn't work until I put it back at "10" which is what Nuxt expected (threw a warning).
I'm trying to create a task to run a sass compilation for the current file but I'm not able to set the output css folder and filename.
The structure of my sass and css files are:
myfolder\css\myfile.css
myfolder\scss\myfile.scss
My current task is:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Compile SCSS",
"type": "shell",
"group": "build",
"command": "sass --load-path ${workspaceFolder}\\vendor\\scss --load-path ${workspaceFolder}\\base\\scss --no-cache --sourcemap=none --update ../scss/${fileBasename}:${fileDirname}/../css/${fileBasenameNoExtension}.css"
}
]
}
the problem is the latest section where I need to put my sass folder/file : my css folder/file
What's the approach here?
I'm currently working on an Angular 6 project containing multiple libraries built and released using ng-packagr. One of those libraries is a component library. As such, it contains multiple component each of them with their own scss. As part of the build of this library with ng-packagr, the html and scss get inlined (and transpiled to css) which is normal and the expected behaviour.
I know that when building a standard Angular app using the #angular-devkit/build-angular:browser there is a flag extractCss that will create a styles.css file as part of the built app containing all of the styles.
Is there a way to do so using ng-packagr?
ng-package.json:
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/storager",
"lib": {
"umdModuleIds": {
"#ngrx/effects": "effects",
"#ng-bootstrap/ng-bootstrap": "ngBootstrap",
"#ngrx/store": "store",
"#ngrx/router-store": "fromNgrxRouter",
"ngrx-store-localstorage": "ngrxStoreLocalstorage",
"#ng-select/ng-select": "ngSelect",
},
"entryFile": "src/public_api.ts",
"styleIncludePaths": ["../", "../styles/scss"]
}
}
Build configs for my lib in angular.json:
"build": {
"builder": "#angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/storager/tsconfig.lib.json",
"project": "projects/storager/ng-package.json"
}
I am trying to add new bower components in sage wp theme, only problem is that i can only add in manyaly in sass?
This is my bower.json
{
"name": "sage",
"homepage": "https://roots.io/sage/",
"authors": [
"Ben Word <ben#benword.com>"
],
"license": "MIT",
"private": true,
"dependencies": {
"bootstrap-sass": "3.3.7",
"pushy": "1.0.0",
"fullpage.js": "2.9.2"
}
}
But in main.scss nothing is added?
// Automatically injected Bower dependencies via wiredep (never manually edit this block)
// bower:scss
#import "../../bower_components/bootstrap-sass/assets/stylesheets/_bootstrap.scss";
// endbower
When you run the bower install command you must add the --save flag to the end of it for it to update everything.
I can't find how to make vendor scripts load before my own scripts. In manifest.json I tried:
"dependencies": {
"main.js": {
"files": [
"scripts/vendor_script.js",
"scripts/custom_script.js"
],
"main": true
},
Doesn't work: vendor script is called after my custom script. Also tried:
"dependencies": {
"plugins.js": {
"files": [
"scripts/vendor/owl.carousel.min.js"
]
},
"main.js": {
"files": [
"scripts/main.js"
],
"main": true
},
Same. Any suggestion?
[EDIT] my current manifest.json file, where I followed the advice from https://discourse.roots.io/t/custom-javascript-in-manifest-json-and-building-out-into-a-single-file/3316:
{
"dependencies": {
"main.js": {
"vendor": [
"scripts/vendor/owl.carousel.min.js"
],
"files": [
"scripts/main.js"
],
"main": true
},
"main.css": {
"files": [
"styles/main.scss",
"styles/vendor/font-awesome.min.css",
"styles/vendor/owl.carousel.min.css"
],
"main": true
},
"customizer.js": {
"files": [
"scripts/customizer.js"
]
},
"jquery.js": {
"bower": ["jquery"]
}
},
"config": {
"devUrl": "http://127.0.0.1/pot/"
}
}
[EDIT #2]
$ node
> require('asset-builder')('./assets/manifest.json').globs.js
require('asset-builder')('./assets/manifest.json').globs.js
[ { type: 'js',
name: 'main.js',
globs:
[ 'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\transition.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\alert.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\button.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\carousel.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\collapse.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\dropdown.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\modal.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\tooltip.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\popover.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\scrollspy.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\tab.js',
'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\bootstrap-sass\\assets\\javascripts\\bootstrap\\affix.js',
'scripts/vendor/owl.carousel.min.js',
'assets/scripts/main.js' ] },
{ type: 'js',
name: 'customizer.js',
globs: [ 'assets/scripts/customizer.js' ] },
{ type: 'js',
name: 'jquery.js',
globs: [ 'D:\\EasyPHP\\www\\pot\\wp-content\\themes\\pot\\bower_components\\jquery\\dist\\jquery.js' ] } ]
The script I'm trying to use is Owl Carousel. If I add the following in head.php it works fine:
<script src="<?php bloginfo("template_url"); ?>/assets/scripts/vendor/owl.carousel.min.js" type="text/javascript" charset="utf-8"></script>
If, instead, I set my manifest.json as shown previously I get a ".owlCarousel is not a function" in Firebug and my slider doesn't work.
Note: I didn't use Bowel, it's not mandatory in regular Sage workflow right? I just copied owl.carousel.min.js into assets/scripts/vendor/.
On a fresh Sage 8 installation I was able to quickly install OwlCarousel using Bower, exactly as described in the Sage documentation without any issue; its script and styles were both correctly included before project scripts and styles.
Font Awesome requires a Bower override because its default Bower main property instructs Bower to use a LESS and a SCSS file; once I set it to just use SCSS it worked fine. Sage 8 ships with a working set of Bower overrides which you should use as an example. See here.
Something else is going wrong with your scripts or your asset builder setup if you're unable to manually add scripts in the correct order. I suspect your asset paths may be incorrect. The best way to troubleshoot and ensure your manifest points to the correct asset paths is to start an interactive node session in a new terminal window.
First run (in your theme dir):
node
Then run (also in your theme dir):
require('asset-builder')('./assets/manifest.json').globs.js
or (still in your theme dir):
require('asset-builder')('./assets/manifest.json').globs.css
The output will display both the assets' paths and the order they're being included.
If you modify manifest.json while running the gulp watch task it may be necessary to halt the task, run a default gulp build, and then restart your gulp watch task.
If you still have difficulty after viewing the asset-builder output using the steps above then please post (either here or on the Roots forum) the output here along with the installation steps you took when installing the vendor scripts and custom scripts you're attempting to use so that someone can attempt to recreate your environment.