I've set up the Grunt workflow as described here:
https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/css-topics/css_debug.html
My local-themes.js looks like this:
➜ m2 git:(master) ✗ cat dev/tools/grunt/configs/local-themes.js
'use strict';
module.exports = {
ac_default: {
area: 'frontend',
name: 'Ac/Default',
locale: 'en_US',
files: [
'css/source/_extend',
],
dsl: 'less'
},
ac_retail: {
area: 'frontend',
name: 'Ac/Retail',
locale: 'en_US',
files: [
'css/source/_extend',
],
dsl: 'less'
},
ac_wholesale: {
area: 'frontend',
name: 'Ac/Wholesale',
locale: 'en_US',
files: [
'css/source/_extend',
],
dsl: 'less'
}
};
I grunt watch successfully triggers when a less file in my child theme gets changed:
➜ m2 git:(master) ✗ grunt watch:ac_retail -v
Initializing
Command-line options: --verbose, --gruntfile=/data/src/m2/Gruntfile.js
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ black-list-generator, clean-black-list, default, deploy, documentation, legacy-build, mage-minify, prod, refresh, spec, static
Running tasks: watch:ac_retail
Loading "grunt-contrib-watch" plugin
Registering "/data/src/m2/node_modules/grunt-contrib-watch/tasks" tasks.
Loading "watch.js" tasks...OK
+ watch
Running "watch:ac_retail" (watch) task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.ac_retail.files exists in config...OK
Live reload server started on *:35729
Watching pub/static/frontend/Ac/Retail/en_US/css/source/_extend.less for changes.
>> File "pub/static/frontend/Ac/Retail/en_US/css/source/_extend.less" changed.
Initializing
Command-line options: --verbose, --gruntfile=/data/src/m2/Gruntfile.js
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ black-list-generator, clean-black-list, default, deploy, documentation, legacy-build, mage-minify, prod, refresh, spec, static
Running tasks: less:ac_retail
Loading "grunt-contrib-less" plugin
Registering "/data/src/m2/node_modules/grunt-contrib-less/tasks" tasks.
Loading "less.js" tasks...OK
+ less
Running "less:ac_retail" (less) task
Verifying property less.ac_retail exists in config...OK
Files: pub/static/frontend/Ac/Retail/en_US/css/source/_extend.less -> pub/static/frontend/Ac/Retail/en_US/css/source/_extend.css
Options: banner="", sourceMap, strictImports=false, sourceMapRootpath="/", dumpLineNumbers=false, ieCompat=false
Reading pub/static/frontend/Ac/Retail/en_US/css/source/_extend.less...OK
Writing pub/static/frontend/Ac/Retail/en_US/css/source/_extend.css.map...OK
File pub/static/frontend/Ac/Retail/en_US/css/source/_extend.css.map created.
Writing pub/static/frontend/Ac/Retail/en_US/css/source/_extend.css...OK
File pub/static/frontend/Ac/Retail/en_US/css/source/_extend.css created
>> 1 stylesheet created.
>> 1 sourcemap created.
Done.
Execution Time (2019-01-16 16:13:35 UTC-8)
loading tasks 42ms ▇▇▇▇▇▇▇▇▇▇▇▇▇ 39%
loading grunt-contrib-less 34ms ▇▇▇▇▇▇▇▇▇▇ 32%
less:ac_retail 31ms ▇▇▇▇▇▇▇▇▇ 29%
Total 107ms
Live reloading pub/static/frontend/Ac/Retail/en_US/css/source/_extend.less...
Completed in 0.729s at Wed Jan 16 2019 16:13:35 GMT-0800 (Pacific Standard Time) - Waiting...
Unfortunately the styles-m.css or styles-l.css files are not updated. Therefore when I refresh the page the changes made in the less files are not reflected on the page.
I posted a ticket in the Magento bug tracker but they have not been particularly helpful.
https://github.com/magento/magento2/issues/20356
My question is. Does anyone here uses Grunt to compile less for a setup with multiple child themes?
In my case the intended theme inheritance looks like this:
ac_retail inherits from ac_default inherits from luma
ac_wholesale inherits from ac_default inherits from luma
From what I can tell the Grunt workflow is the only workflow that is actually suitable for theme development. Server and client side compilation are way too slow to use for development.
Finally figured it out. The documentation has errors. You need to specify the parent themes style files, even if your child theme has it's own root source files, if you want to re-compile styles-m.css and styles-l.css, when the child themes less files change. This local-themes.js ended up working for me:
>>'use strict';
>>module.exports = {
ac_default: {
area: 'frontend',
name: 'Ac/Default',
locale: 'en_US',
files: [
'css/styles-m',
'css/styles-l',
],
dsl: 'less'
},
ac_retail: {
area: 'frontend',
name: 'Ac/Retail',
locale: 'en_US',
files: [
'css/styles-m',
'css/styles-l',
],
dsl: 'less'
},
ac_wholesale: {
area: 'frontend',
name: 'Ac/Wholesale',
locale: 'en_US',
files: [
'css/styles-m',
'css/styles-l',
],
dsl: 'less'
}
};
adding
'css/styles-m',
'css/styles-l',
fixed it for me too. Thanks for this
Related
I'm trying to get svelte material UI working with snowpack.
I have installed Snowpack and Snowpacks svelte template like so:
npm install --save-dev snowpack#next
npx create-snowpack-app xpapp --template #snowpack/app-template-svelte
This works, the sample svelte page shows up. Next I followed the Svelte Material UI instructions to "bundle this in your own code" as cited on the Usage chapter in the instructions here: https://github.com/hperrin/svelte-material-ui#usage
So I installed Sass and configured it in my snowpack.config.json file like this:
{
"extends": "#snowpack/app-scripts-svelte",
"scripts": {
"build:scss": "sass"
},
"devOptions": {},
"installOptions": {}
}
I followed the (very concise) instructions here: https://www.snowpack.dev/#sass
I've also added an empty src/theme/_smui-theme.scss file to my source files as the instructions say, and I installed the nessecary #smui components.
The problem is that I'm currently getting this error when starting the snowpack dev server:
> snowpack dev
Snowpack Dev Server (Beta)
NOTE: Still experimental, default behavior may change.
Starting up...
⠙ snowpack installing... #smui/icon-button, #smui/top-app-bar, svelte/internal
✘ /home/erik/Projects/svelte-xpapp/xpapp/node_modules/#smui/icon-button/_index.scss
Error: Unexpected character '#' (Note that you need plugins to import files that are not JavaScript)
at error (/home/erik/Projects/svelte-xpapp/xpapp/node_modules/snowpack/node_modules/rollup/dist/shared/rollup.js:161:30)
at Module.error (/home/erik/Projects/svelte-xpapp/xpapp/node_modules/snowpack/node_modules/rollup/dist/shared/rollup.js:15120:16)
at tryParse (/home/erik/Projects/svelte-xpapp/xpapp/node_modules/snowpack/node_modules/rollup/dist/shared/rollup.js:15009:23)
at Module.setSource (/home/erik/Projects/svelte-xpapp/xpapp/node_modules/snowpack/node_modules/rollup/dist/shared/rollup.js:15410:30)
at ModuleLoader.addModuleSource (/home/erik/Projects/svelte-xpapp/xpapp/node_modules/snowpack/node_modules/rollup/dist/shared/rollup.js:17460:20)
at async ModuleLoader.fetchModule (/home/erik/Projects/svelte-xpapp/xpapp/node_modules/snowpack/node_modules/rollup/dist/shared/rollup.js:17521:9)
at async /home/erik/Projects/svelte-xpapp/xpapp/node_modules/snowpack/node_modules/rollup/dist/shared/rollup.js:17491:36
at async Promise.all (index 0)
at async ModuleLoader.fetchModule (/home/erik/Projects/svelte-xpapp/xpapp/node_modules/snowpack/node_modules/rollup/dist/shared/rollup.js:17522:9)
at async Promise.all (index 0)
It seems that the #import statements in Material UI's _index.scss aren't recognized. I figure Snowpack should interpret/transpile .scss files, but it doesn't seem to be doing that.
So I came across the same problem using Svite as well as Snowpack. I was able to use the bare implementation:
// component.svelte <script>
import Button, { Label } from '#smui/button/bare'
import '#smui/button/bare.css'
That's all that's required with Svite.
With Snowpack, I needed to add rollup-plugin-svelte and update snowpack.config.js
// snowpack.config.js
module.exports = {
// ...
installOptions: {
rollup: { plugins: [require('rollup-plugin-svelte')()] }
},
// ...
}
I got it working with these install options:
installOptions: {
rollup: {
plugins: [
require("rollup-plugin-svelte")({
include: ["./node_modules"],
}),
require("rollup-plugin-postcss")({
use: [
[
"sass",
{
includePaths: ["./src/theme", "./node_modules"],
},
],
],
}),
],
},
},
Unfortunately, you'll have to run npx snowpack dev --reload for changes to the theme to take effect.
This won't extract css into .css files.
I also got an error message with the Dialog component during a production build.
Here is a full example: https://github.com/LeanderG/svelte-smui
After installing the gatsby-plugin-sass module:
When I try to run gatsby build, I get the following error:
ERROR
Unknown error from PostCSS plugin. Your current PostCSS version is 6.0.23, but autoprefixer uses 7.0.26. Perhaps this is the source of the error below.
ERROR #98123 WEBPACK
Generating development JavaScript bundle failed
Browser queries must be an array or string. Got object.
File: src/indexs.sass
failed Building development bundle - 9.200s
I have been working on a resolution to this for hours. I have tried:
custom webpack rules in gatsby-node.js for sass files
reading, re-reading, and re-re-reading the instruction on gatsby's site
updating PostCSS using npm in every way I know how
So far, nothing has worked.
Why is it so complicated to get sass working with gatsby? When the documentation on gatsby's site makes it seem so easy?
Any suggestions what I can do to get this working?
in gatsby-node.js:
exports.onCreateWebpackConfig = ({
stage,
rules,
loaders,
plugins,
actions,
}) => {
// console.log('rules',rules)
// console.log('rules.css',rules.css())
// console.log('rules',rules.postcss())
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
'css-loader',
// Compiles Sass to CSS
'sass-loader',
],
},
],
},
plugins: [
plugins.define({
__DEVELOPMENT__: stage === `develop` || stage === `develop-html`,
}),
],
})
}
In gatsby-config.js:
{
resolve: `gatsby-plugin-postcss`,
options: {
postCssPlugins: [require(`postcss-preset-env`)({ stage: 0 })],
},
},
`gatsby-plugin-sass`,
the sass import line in gatsby-browser.js:
import "./src/indexs.sass"
Using sass instead of node-sass saved my day.
remove node-sass
npm uninstall node-sass
or
yarn remove node-sass
and add sass aka dart-sass
npm install --save-dev sass
or
yarn add sass
then edit gatsby-config.js
plugins: [
{
resolve: `gatsby-plugin-sass`,
options: {
implementation: require("sass"),
},
},
]
now run gatsby develop
:)
I'm a bit late to the party but hopefully this might help someone.
I have Sass setup and working with Gatsby without to much extra config required.
Install both node-sass and gatsby-plugin-sass via npm.
npm install --save node-sass gatsby-plugin-sass
Include gatsby-plugin-sass in your gatsby-config.js file in plugins: [] as below with any other Gatsby plugins you maybe using.
module.exports = {
siteMetadata: {
title: `#`,
description: `#`,
author: `#`,
},
plugins: [
`gatsby-plugin-sass`,
],
}
Write your styles as .sass or .scss files and import your main styles.scss (or whatever you prefer to name it) either in your main Layout.js file or gatsby-browser.js file as below using the path to the location of your styles.scss file.
import "./src/styles/styles.scss"
I hope this works for you but if you have any other trouble add a comment and I'll try to reply back.
I hope someone chimes in on this to show how exactly to set up gatsbys sass plugin. I could not get it to work at all.
But I did find a workaround in my case:
I removed gatsby-plugin-sass from the plugins array in gatsby-config.js, turning it off (but I did not uninstall it using npm)
I installed postcss-node-sass and postcss
I added this info to the plugins array in gatsby-config.js:
{
resolve: `gatsby-plugin-postcss`,
options: {
postCssPlugins: [
require(`postcss-preset-env`)({ stage: 0 }),
require(`postcss-node-sass`)(),
],
},
},
I added a custom rule for webpack in gatsby-node.js:
exports.onCreateWebpackConfig = ({
stage,
rules,
loaders,
plugins,
actions,
}) => {
// console.log('rules',rules)
// console.log('rules.css',rules.css())
// console.log('rules',rules.postcss())
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
'css-loader',
// Compiles Sass to CSS
'sass-loader',
],
},
],
},
plugins: [
plugins.define({
__DEVELOPMENT__: stage === `develop` || stage === `develop-html`,
}),
],
})
}
Here is a basic view of my "watch" grunt task:
module.exports = function(grunt){
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);
grunt.initConfig({
watch: {
options: {
livereload: true,
},
gruntfile:{
files:['gruntfile.js'],
tasks:['default']
},
html: {
files: ['index.html', 'assets/templates/*.html'],
tasks: ['default']
},
js: {
files: ['assets/js/*.js'],
tasks: ['default']
},
sass: {
options:{
livereload:false
},
files:['assets/sass/*.scss'],
tasks:['buildcss'],
},
css:{
files:['assets/sass/*.scss'],
tasks:[]
},
},
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['htmlhint','buildjs', 'buildcss', 'browserSync', 'watch','serve']);
};
So I have buildcss that compiles and minifies my scss into a master.css file. I've set up watch to watch the scss for changes, run the buildcss task, and then run the default task once the master.css file is updated. Then it should then refresh the page.
However, whenever I make a change to the scss file and save it, terminal shows no file updates even though it is apparently "watching files...". The only files that show as updated when I make changes are the html files: index and templates. It makes no sense to me. Sorry, I'm configuring Grunt for the first time here.
I was confusing watch and browserSync instead of using them together. First, I had to add watchTask: true, to browserSync, then I had to ensure that browserSync was being called before watch, and then I had to add the snippet of code the console prodded me to add to my index.html. Now it works perfectly. Here is the site I used to find my way: http://blog.teamtreehouse.com/getting-started-with-grunt
I'm using the following grunt tasks
grunt-sass
grunt-contrib-watch
grunt-autoprefix
node-bourbon
(there are a few other tasks, such as uglify, spritesmith, and haml, which i have left out of this example)
My grunt file looks like this:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
options: {
sourceMap: true,
outputStyle: 'compressed',
imagePath: 'assets/css/img',
includePaths: require('node-bourbon').includePaths
},
dist: {
files: {
'assets/css/app.css': 'assets/sass/app.scss'
}
}
},
autoprefixer: {
options: {
browsers: ['last 2 version', 'ie 8', 'ie 9'],
silent : false
},
dev: {
src: 'assets/css/app.css',
dest: 'assets/css/post.css'
},
},
watch: {
options: {
livereload: true
},
sass: {
files: ['assets/sass/**/*.scss', 'assets/sass/*.scss'],
tasks: ['sass:dist', 'autoprefixer:dev']
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.registerTask('default', ['watch', 'sass']);
};
This is working. However, if there is an error in my sass file nothing is reported. For instance if I try and use an $variable that doesn't exist, no errors are reported in my terminal
Here are two subsequent logs, the first compiles successfully with no errors. The second doesn't compile (as there is an undefined variable in the scss file)
Completed in 1.712s at Sun Sep 28 2014 15:23:17 GMT+0100 (GMT Daylight Time) - Waiting...
>> File "assets\sass\app.scss" changed.
Running "sass:dist" (sass) task
File assets/css/app.css created.
File assets/css/app.css.map created.
Running "autoprefixer:dev" (autoprefixer) task
File assets/css/post.css created.
Done, without errors.
C:\wamp\www\_bp2>grunt
Running "watch" task
Waiting...
>> File "assets\sass\app.scss" changed.
Running "sass:dist" (sass) task
Completed in 1.656s at Sun Sep 28 2014 15:29:25 GMT+0100 (GMT Daylight Time) - Waiting...
Does anyone know why no errors are being logged?
I'm in the process of rebuilding my sass boilerplate to use libsass and bourbon instead of compass. So I'm expecting to come across loads of errors during the process, so I really need to know what these errors are.
Thanks
I'm trying to run my karma (version v0.10.2) unit tests on teamcity (version 7.1).
When I run karma start --reporters teamcity --single-run I get the following error:
Can not load "teamcity", it is not registered! Perhaps you are missing some plugin?
I have installed the karma-teamcity-reporter module, but that hasn't helped.
The following are installed in my local node_modules folder:
karma
karma-chrome-launcher
karma-coffee-preprocessor
karma-coverage
karma-firefox-launcher
karma-html2js-preprocessor
karma-jasmine
karma-phantomjs-launcher
karma-requirejs
karma-script-launcher
karma-teamcity-reporter
Here is my karma.conf.js:
I'm running karma version v0.10.2. Here's my karma.conf.js:
module.exports = function(karma) {
karma.set({
// base path, that will be used to resolve files and exclude
basePath: '../../myapplication.web',
frameworks: ['jasmine'],
plugins: [
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
'karma-phantomjs-launcher'
],
// list of files / patterns to load in the browser
files: [
'Scripts/jquery/jquery-2.0.2.min.js',
'Scripts/jquery-ui/jquery-ui-1.10.3.min.js',
'Scripts/daterangepicker/daterangepicker.js',
'Scripts/angular/angular.js',
'Scripts/angular/restangular/underscore-min.js',
'Scripts/angular/restangular/restangular-min.js',
'Scripts/angular/angular-*.js',
'Scripts/angular/angular-test/angular-*.js',
'Scripts/angular/angular-ui/*.js',
'Scripts/angular/angular-strap/*.js',
'Scripts/angular/angular-http-auth/*.js',
'Scripts/sinon/*.js',
'Scripts/moment/moment.min.js',
'uifw/scripts/ui-framework-angular.js',
'app/app.js',
'app/**/*.js',
'Tests/unit/**/*.js'
],
// list of files to exclude
exclude: [
'Scripts/angular/angular-test/angular-scenario.js'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters: ['progress', 'coverage', 'teamcity'],
preprocessors : {
'app/**/*.js': ['coverage']
},
coverageReporter : {
type: 'html',
dir: 'Tests/coverage/'
},
// web server port
port : 9876,
// cli runner port
runnerPort : 9100,
// enable / disable colors in the output (reporters and logs)
colors : true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel : karma.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch : true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout : 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun : true
});
};
If I run karma start karma.conf.js it runs correctly. What am I doing wrong?
Turned out I needed to add karma-teamcity-reporter to the plugins section to get this to work:
...
plugins: [
'karma-teamcity-reporter',
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
'karma-phantomjs-launcher'
],
...