Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem linking to assets. #740

Closed
dadambickford opened this issue Aug 11, 2013 · 19 comments
Closed

Problem linking to assets. #740

dadambickford opened this issue Aug 11, 2013 · 19 comments

Comments

@dadambickford
Copy link

Having trouble linking to our css. We have tried putting it in different folders, linking to different levels of folders, using to input, etc. I'm sure it's something simple we're overlooking but as of now, we're stumped.

Thanks in advance.

@dadambickford
Copy link
Author

cc: @OscarGodson @sebnitu

@mikermcneil
Copy link
Member

Hi @dadambickford- you'll want to put your client side assets in the assets directory. At lift-time, Grunt copies the files in assets into a hidden folder called .tmp/public which is your web root. Hope that helps!

@OscarGodson
Copy link

So if we had /assets/css/baseweb.css in our project we could access the file by hitting localhost:1337/css/baseweb.css? Or, if we had a file in /assets/baseweb.css it'd be localhost:1337/baseweb.css?Or, is it /public/*? Those all don't work. I just retried all of them. On all of our machines we just get Not Found. A little more explanation of how to just straight up link to static files would be super helpful. All three of us tried for 2hrs yesterday before spinning up a python simple server in the project root just so we could link to the static files.

@OscarGodson
Copy link

Also, there is no /public in my webroot. Just disk.db:

image

Sails is currently running.

@OscarGodson
Copy link

@mikermcneil bump? :\ we're not having any luck and there's no .tmp/public. I tried IRC and nobody responded. We're basically stuck since we can't serve up assets.

@particlebanana
Copy link
Contributor

All of the assets in Sails are handled by the Grunt process. So when Sails is lifted it's simply starting up the Grunt service by running grunt I believe which will trigger the default task in the Gruntfile.js. The first place to start debugging would be there to see if you can run the Grunt task without Sails. The relevant task in the boilerplate Gruntfile is compileAssets: https://github.com/balderdashy/sails/blob/master/bin/boilerplates/Gruntfile.js#L395-L400

See if you can run it from the command line and if it gives you any errors. That would be a good first step.

grunt compileAssets

That command should create the .tmp/public folder and copy all of your assets into it.

@sgress454
Copy link
Member

You can also see output from Grunt during the Sails lift process if your logging level is set to "verbose". You can change the logging level via your app's config/log.js file.

@OscarGodson
Copy link

@sgress454 There's no config/log.js file. I did some digging and I found where I put it. Looks like the config/application.js file.

@particlebanana We get an error:

verbose: Grunt :: grunt-cli: The grunt command line interface. (v0.1.9)

Fatal error: Unable to find local grunt.

If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:

http://gruntjs.com/getting-started

That shows up when running that command manually and in the verbose logging. I tried npm install grunt-cli. Still nothing. Tried sudo npm install -g grunt-cli since it warned it preferred global, but still nothing. Then I realized, there's no Gruntfile.js. This is probably because of the upgrade. I made a new app, copied the gruntfile and put it in our project. Still nothing. Everything seems completely fine tho:

image

Am I missing something?

@OscarGodson
Copy link

Finally. I needed to install grunt not grunt-cli (from the grunt docs it says to install npm install -g grunt-cli). Why was this not included in the Sails upgrade and why does it use Grunt and not grunt-cli?

@particlebanana
Copy link
Contributor

You need both. grunt is installed locally in your project's node_modules folder and grunt-cli is installed globally and contains the bin.

The issue with the missing config/log.js and Gruntfile.js seems to be from a migration from a 0.8.x codebase to a 0.9.x codebase and not running through the migration guide. You will need to copy some files over to the old codebase in order for it to work correctly.

Sails 0.9.x Migration Guide

@craig-coles
Copy link

I had this problem too, but noticed that I only had one line of code in each of the asset files that weren't showing up in the .tmp/public directory when I ran sails lift (I was just doing some testing) ... once I added more lines to the files they worked. Hope this helps

@craig-coles
Copy link

also try (from the CLI) sails lift --dev should get rid of any cache issues

@OscarGodson
Copy link

This is working now so you can close this!

@ninjasort
Copy link

Is there a reason you're injecting scripts in this way vs just using the grunt-contrib-requirejs plugin?

@OscarGodson
Copy link

@cameronjroe because we don't want to use Require or Grunt :) If you're a require user and want to use Grunt I'm sure that'd work fine.

@ninjasort
Copy link

But you are using Grunt.. and are you not writing your scripts in amd?

@OscarGodson
Copy link

Nope, we're not using Grunt at all. Here's the Sails' Grunt file for our project:

module.exports = function (grunt) {
// Keep here to make make Sails shut up
grunt.registerTask('default', []);
};

And the only reason that's there is because Sails requires at least a default task or it complains.

We're using NPM + Browserify + Jake. We have Browserify just build different packages and require them async.

@ninjasort
Copy link

Interesting. Browserify looks awesome. The current Gruntfile doesn't leave much room for customization out of the box. I'm basically killing most of it to substitute with the Requirejs plugin. :(

@ninjasort
Copy link

We also commonly use compass which is actually part of the grunt-contrib suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

7 participants