Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Assuming you already have ruby, bundler, node and npm installed, it is very easy to create a sub-theme and working environment that includes:
- dependency management using a gemfile for bundler and package.json for npm
- gulp for compiling your SASS files, checking your SCSS syntax, and other things...
drush dl --select zen
( choose 7.x-6.x-dev )
drush en zen -y
drush cc all
drush zen "sub-theme"
( --without-rtl doesn't seem to work )
cd sites/all/themes/sub-theme
bundle install
npm install
(Install gulp for global/command line use )
npm install -g gulp
gulp
drush cc all
( If you get PDO exception, you need to run this, but supposedly npm install should have already run it: )
find node_modules/ -name '*.info' -type f -delete
gulp watch
( WARNING: Setting $box-sizing to border-box will fail for legacy IE browsers because the $box-sizing-polyfill-path is empty.)
( Change $critical-usage-threshold to be .3 on line 28 of sub-theme/sass/init/_variables.scss )
( Notice that gulp watch works. )
Comments
Comment #2
JohnAlbinComment #3
tstermitzWent through pprocedure on clean Digital Ocean droplet. Need to use npm to install gulp globally:
npm install -g gulp
Comment #4
JohnAlbinInstead of installing node.js modules globally, we should link to this article on how to use node binaries that are installed locally. https://www.previousnext.com.au/blog/getting-started-front-end-automatio...
Comment #5
JohnAlbinComment #6
JohnAlbinComment #8
JohnAlbinComment #9
MustangGB CreditAttribution: MustangGB commentedFollowed the instructions, got as far as "npm install", it tells me npm isn't installed but I can install it with "sudo apt-get install npm", so I do this and run "npm install" again and it spews out the following:
Any idea what's going wrong here?
Is a newer version of npm than 1.4.21 required?
If so should it be stated somewhere, perhaps with install instructions?
Test server is running Ubuntu 15.10
Comment #10
MustangGB CreditAttribution: MustangGB commentedAfter installing bundler and updating nodejs(/node/npm) binaries from https://github.com/nodesource/distributions it look like the "npm install" has now worked.
Also rather than having to alias "npm bin" why not just add a script entry for gulp so we can just use "npm run gulp" instead?
I'm also seeing some strange things when "watching", like the css appearing broken in the browser after starting to watch but before editing any scss files, and some changes pulling through fine (changing body colour to red) but other changes not pulling through (changing body colour to blue), so I just want to confirm that my setup should be working before posting any issues, right?
Comment #11
JohnAlbinThanks for testing the docs!
Yeah, I noticed that watch issue last night. #2627716: gulp watch task breaks CSS before they are edited
Never tried that before. Hmmm… looks like that is one of the less-popular solutions to the same problem. http://stackoverflow.com/questions/9679932/how-to-use-package-installed-...
The npm-exec alias is the top answer to that question. Probably because it works for any node.js binary.
Comment #12
MustangGB CreditAttribution: MustangGB commentedYea my reasoning was basically the same as that jpoveda chap that replied to the answer you linked. Install and go is much less of a faff than install, mess about configuring things locally, re-sourceing, etc.
Comment #13
JohnAlbinOk. I'll consider it for a bit. Then probably do it.
Comment #14
skyredwangI thought scss-lint is for Ruby and Compass while sass-lint is for Node. No?
Comment #15
MustangGB CreditAttribution: MustangGB commented@skyredwang
I believe sass-lint is still the plan, but it isn't ready for primetime yet, see https://github.com/sasstools/sass-lint/issues/305 and #2595997: Replace Ruby-based scss_lint with node.js-based sass-lint, so we're stuck scss_lint and Ruby for now.
Comment #16
skyredwang@MustangGB, Thanks for the information. I will just not/disable lint until sass-lint becomes ready. Easier than maintaining both Ruby stack and Node stack. Maybe this is good for people new to Node centric front end dev.
Comment #17
skyredwangI feel the front-end development build tools required for Zen 6.x are quite a lot, which I don't feel comfortable to install them on my laptop. Also, installing that many things is not easy for training.
I am going to write a Docker image for this. One command should be able to solve all this. And it should work for all OS.
Comment #18
skyredwangThe command below will take care all the installation
1. Go to the subtheme folder
2.
docker run -it --rm -v "$PWD":/usr/src/app -w /usr/src/app node npm install
The command below will do the gulp watch
1. Go to the subtheme folder
2.
docker run -it --rm -v "$PWD":/usr/src/app -w /usr/src/app node ./node_modules/.bin/gulp watch
Comment #19
skyredwangIt might be cool, if we can let gulp to serve the style guide and do live reload?
The code below is the just demoing the idea, based on Polymer Starter Kit gulpfile.js
Then, one more docker command, we will be able to see the styleguide site:
docker run -it --rm --name zen-dev -v "$PWD":/usr/src/app -w /usr/src/app -p 80:5000 node ./node_modules/.bin/gulp serve
Just open a browser and go to http://localhost
Comment #20
JohnAlbin> It might be cool, if we can let gulp to serve the style guide and do live reload?
The new gulp watch does live reload of the styles on the Drupal site itself, which (since the theme is inside the Drupal file structure) can include the style guide.
See #2624172: Add browser-sync gulp task
Comment #21
codemannWe're having problems trying to get the latest 7.x-6.x-dev installed.
I tried to gather as much information as possible, hopefully someone can push us in the right direction.
This is all done from a development server in our datacenter.
Some version information :
I install a sub-theme with drush and cleared the cache.
After that I check with bundle if everything is up-to-date :
Then I run npm install from withing my sub-theme.
There were some (deprecated) warnings when running this, so I ran it a second time and got :
The fsevents warning seems to be normal for a Linux system?
The first warning I will run manually :
Then I tried running gulp watch :
This refers to line 161 in gulpfile.js, but no idea why this errors :
I also tried running it with npm-exec :
And with bundle :
Comment #23
JohnAlbin> We're having problems trying to get the latest 7.x-6.x-dev installed.
I just pushed some changes to the gulpfile.js that alters the very lines you mention. You'll have to delete your node_modules folder and npm-shrinkwrap.json file and re-install:
1.
npm install
2.
bundle install
3. If you work with other people on this project:
a. run
npm shrinkwrap --dev
and commit your npm-shrinkwrap.json to Git so others on your project get the exact same versions of the node.js tools.b. commit your Gemfile.lock file to Git so others on your project get the exact same versions of the Ruby Gem tool.
Comment #24
codemannIt got me a but further, but I'm still getting errors while running gulp watch
Comment #25
codemannToday I finally had some time to dig more into the whole Zen v6 thing.
What an incredible work, and I loved your "All hail the robot overlords" presentation John!
After watching that and reading a lot of stuff I'm starting understanding where you guys are going to a lot better and I was able to fix my previous issue as well. Adding this to the Gemfile fixed it for me :
I'm not completely sure I understand the reason correctly, but I think it is because json is also included into ruby by default, but by adding this line you make it use the gem that you installed. Correct me if I'm wrong here, I'm trying to learn and understand it better!
Comment #26
skyredwangI tested 7.x-6.x-dev packaged on Dec.28th.2015 with node 5.3.0; it works well. What else is needed in this issue?
Comment #27
skyredwangSomething strange in the node_module folder causes drush 8.0.1 and Apache to "segment fault". I haven't figured it what the problem is.
Comment #28
skyredwangI see this line is already in package.json
"postinstall": "find node_modules/ -name '*.info' -type f -delete",
But, I have to manually delete this file:
node_modules/json3/coverage/lcov.info
Not sure why yet.
Comment #29
skyredwangDuring the installation, I ran into the error below:
npm WARN lifecycle zen-subtheme@1.0.0~postinstall: cannot run in wd %s %s (wd=%s) zen-subtheme@1.0.0 find node_modules/ -name '*.info' -type f -delete /usr/src/app
That explains #28
Comment #30
arnoldbird CreditAttribution: arnoldbird commentedI'm running into something similar to #29. I'm seeing...
npm WARN package.json scss-lint@0.0.0 No repository field.
npm WARN cannot run in wd zen-subtheme@1.0.0 find node_modules/ -name '*.info' -type f -delete (wd=/var/www/global_social/ryan_code/themes/global_social)
I get the above errors when I run...
sudo npm install
If I then run...
gem list
...I see that many dependencies listed in package.json are not getting installed.
I'm following the README.txt instructions.
Comment #31
arnoldbird CreditAttribution: arnoldbird commentedI tried following the instructions in the issue summary, but when I run...
sudo gulp
...I get this error...
$ sudo gulp
[14:41:11] Using gulpfile /var/www/my_site/some_path/themes/my_site/gulpfile.js
[14:41:11] Starting 'clean:css'...
[14:41:11] Starting 'clean:styleguide'...
[14:41:11] Starting 'styleguide:chroma-kss-markup'...
[14:41:11] Starting 'lint:sass'...
[14:41:12] Starting 'lint:js'...
[14:41:12] Finished 'lint:js' after 561 ms
[14:41:12] Finished 'clean:css' after 891 ms
[14:41:12] Starting 'styles:production'...
[14:41:12] Finished 'clean:styleguide' after 1.15 s
[14:41:13] chroma-kss-markup.hbs 17.46 kB
[14:41:13] Finished 'styleguide:chroma-kss-markup' after 1.49 s
[14:41:13] Starting 'styleguide'...
/var/www/my_site/some_path/themes/my_site/node_modules/gulp-autoprefixer/node_modules/postcss/lib/lazy-result.js:157
this.processing = new Promise(function (resolve, reject) {
^
ReferenceError: Promise is not defined
at LazyResult.async (/var/www/my_site/some_path/themes/my_site/node_modules/gulp-autoprefixer/node_modules/postcss/lib/lazy-result.js:157:31)
Comment #32
arnoldbird CreditAttribution: arnoldbird commentedSimilar to #10, the instructions in the issue summary do work for me once I upgrade node. I did so with...
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
I can't vouch for that being the best/safest way. Just something I found online.
Comment #33
skyredwangI found the fix to my problem in #29. Now, I have written this guide, which makes the whole process very easy: https://insready.com/en/blog/containerize-zen-style-guide-driven-develop...
Comment #34
frobAfter reading through this issues, I am not sure what all is left to do. It looks like this is the only issue left before a release of 7.x-6.x
Comment #35
JohnAlbinOh, dang it. That means one of the modules we are using requires Node.js 4.0.0 or later. I'll have to update the package.json to drop support for Node.js 0.12.
Yep.
Comment #37
JohnAlbin@arnoldbird: You don't need to use sudo on those commands. In fact, its highly dangerous to do so, because you are letting a npm package run its code as super user on your computer.
Comment #38
MustangGB CreditAttribution: MustangGB commentedI still think the docs aren't clear enough, I went through the readme again on beta1, as in #9, and got unstuck at exactly the same point.
Could it not just list everything that must be installed to get this working?
Comment #40
JohnAlbinI've updated the instructions.
Comment #41
JohnAlbinComment #42
JohnAlbin