I am using IntelliJ to edit a Next.js website.
IntelliJ IDEA 2020.2.1
Next.js 9.5.3-canary.23
Next.js static file serving uses a /public directory as a container for static assets, but when publishing a Next.js site, the contents of the public directory are hosted at the root of the site.
So, as shown in the linked doco, an image that exists in the codebase at /public/my-image.png is addressed by an URL path of src="/my-image.png".
This confuses IntelliJ and it shows a warning that it can't resolve the directory of the img src:
I tried marking the /public directory as a "Source root" or a "Resources root" - but that didn't make the warning go away.
I also tried adding the /public directory as a "Content root", but IntelliJ doesn't want to do that because it overlaps with the root directory of the module, which is already a content root.
Is there any way to tell idea to look in the /public directory for statically referenced assets like this?
I've had the same problem. In my case, "Mark Directory as > Resource Root" worked well.
Before...
Right click ./public. Then Mark Directory as > Resource Root
After...
Image loads.
Related
I have a php file under of static folder.
How can i browse the php file?
I tried to use a proxy on config, but its not working
/pages
/static
test.php
How could i browse it
localhost:port/[proxy]/test.php
Thanks
I guess you would need a webserver to handle your .php file.
/static folder is for static content.
This is what i found in the documentation:
If you don't want to use Webpack assets from the assets directory, you can create and use the static directory (in your project root folder).
All included files will be automatically served by Nuxt and are
accessible through your project root URL. (static/favicon.ico will be
available at localhost:3000/favicon.ico)
https://nuxtjs.org/guide/assets/#static
I have a web site project folder that looks something like this:
/
/css/
/includes/public.cfm
/js/jquery.js
index.cfm
My index.cfm file includes the content from the /includes/public.cfm file. The public.cfm file has references to various .css and .js files in it like this:
/includes/public.cfm
------------------------
<base href="http://localhost/mysite/">
<script type="text/javascript" src="js/jquery.js"></script>
The problem is that IDEA can't find the file /js/jquery.js and shows a "cannot resolve directory" inspection error even though the file does exist in the project structure.
How can I tell IDEA to always look at my project root for resolving directory locations? It would be great if it could first look relative to the current folder and then look relative to the project root.
Note: when the web site gets deployed to production, it will reside at www.mydomain.com but it should also be able to reside in a sub folder for development purposes.
I am working with a project with a single "Static Web" module in IntelliJ IDEA 13.1.4 with the PHP plugin (NOT PHPStorm).
Given the following directory structure:
-ProjectX
--application
--www
I marked the "www" folder as "resources root". The "ProjectX" folder is the "content root".
HTML references to resources are correctly resolved only in files from within the "www" folder, not when the "application" folder. Annotated screenshots:
This works in PHPStorm, but not IntelliJ IDEA. How do I get the desired behavior in IntelliJ so references will resolve from all project folders?
After playing with it for a while, I may have a solution.
It appears that BOTH "ProjectX" and "www" have to be marked in order for this to work. If you first mark "www" as a resources root, and THEN mark the parent/content-root folder as a resources root, the reference will resolve.
If this was obvious to anyone out there, please explain. Or is there a more appropriate solution?
SCREENSHOT:
In my /var/www/ i have:
my_project
|-app
|-controllers
|-models
|-views
|-core
|-css
|-js
|-public
|-index.php
I have set up "DirectoryRoot" to:
/var/www/my_project/public/
Now when i open web page in browser my views are loaded but links to files in css and js folders don't work. It looks like I can't go one directory up. What am i doing wrong ?
How can I set where IntelliJ looks for files referenced in a JSP? If I have
<jsp:include page="/foo/bar" />
it cannot resolve directory foo.
It looks like Settings > Web Contexts deals with this, but when I go there, it says
No web directories found
You should configure a web facet in your project settings, then configure the directory containing foo as a "Web Resource Directory". If this is your root directory, set the "Path Relative to Deployment Root" to /.
See the official doc for more info.