Can be the "public" folder moved inside the "src" folder? - next.js

Docs that there is a possibility to use src folder in Next.js.
I think this is a good pattern to separate actual business logic from app configs.
It would feel natural to me to put the public folder also under the src folder.

No. The public folder has to be in root folder
Config files like next.config.js and tsconfig.json should be inside the root directory, moving them to src won't work. Same goes for the public directory

Related

Moving Pages folder in Next.js application to src folder

In a create-next-app Next.js application, I want to move the pages folder in the root directory to a src folder. I added a jsconfig.json with the code (below), however now I get the error message "404 | This page could not be found." Anyone have any insight? (Sorry beginner to web development)
{
"compilerOptions": {
"baseUrl": "src"
}
}
Nextjs by default supports moving /pages to src/ folder.
Create a /src folder in the root directory.
Delete the /.next folder
Move /pages to the /src folder
Remember package.json, .gitignore and other config files needs to be in the root directory and should not be moved to the /src folder.
Once that is done just run the command $ npm run dev or $ yarn dev , so you can view it on your localhost.
More: https://nextjs.org/docs/advanced-features/src-directory
In case you are using NextJS + TailwindCSS, you need to change the following in tailwind.config.js after moving files under the src directory:
module.exports = {
content: [
'./pages/**/*.{js,ts,jsx,tsx}',
'./components/**/*.{js,ts,jsx,tsx}',
],
...
...
You need to stop the server and then do npm run dev. That solved my problem when I moved things into the src directory and started getting 404 pages.
content: [
'./src/pages/**/*.{js,ts,jsx,tsx}',
'./src/components/**/*.{js,ts,jsx,tsx}',
],
replace above in case of src
As #Thierry mentioned in the comments, according to the docs "Pages can also be added under src/pages as an alternative to the root pages directory. The src directory is very common in many apps and Next.js supports it by default."
So, src/pages will be ignored if pages is present in the root directory.
More at the official docs: https://nextjs.org/docs/advanced-features/src-directory
src/pages will be ignored if pages is present in the root directory
Update tsconfig.json (if you use Typescript)
"paths": {
"#/*": ["./src/*"]
}
Reload npm run dev

How to Change Default GWTBootstrap3 Theme

I'm trying to change the default GWTBoostrap3 theme without any luck. I found this link. I have done what is explained but I don't see any change. Where must the 'resource' folder be located? I created this folder inside my WAR/nameofmyapp folder, put my theme.css file and modified my .gwt.xml file by adding these lines:
<public path='resource'>
<include name='css/*.css'/>
</public>
<stylesheet src='css/theme.css'/>
I downloaded these CSS theme files with still no changes. What am I doing wrong?
Read about Public Path:
Modules can specify which subpackages are public, causing the named
package and its subpackages to be added to the public path. The public
path is the place in your project where static resources referenced by
your GWT module, such as CSS or images, are stored. When you compile
your application into JavaScript, all the files that can be found on
your public path are copied to the module’s output directory. (...)
When referencing public resources from a Module XML File, just use the
relative path within the public folder, the module’s base URL will be
prepended automatically. (...)
You have specified your public package to be named resource and to include css/*.css files. So you should put the theme.css file to full.path.to.the.package.resource.css package.
In other words, the path attribute of the public tag is relative to the folder where the <module>.gwt.xml file is.

Mount Path for static assets in Meteor

When running a Meteor application the assets in <script> tags are relative to the root path, like <script type="text/javascript" src="/app/routes.js?baa7082cd1947c1ebf3cdabc08bfe8701bd770af"></script>
I'm trying to point an nginx server to it from a different path, e.g.example.com/my-app but since the assets are still pointing relative to the root path they don't get loaded.
E.g. example.com/app/routes.js instead of example.com/my-app/routes.js
In webpack I could just specify a publicPath and the assets will point relative to it. Is there something similar that I can do in Meteor?
The files should be in public directory in the root.
For example if the structure is public/images the src of image will be /images/imagefile.jpg. Same for javascript.
The files can be referred as /assets/public/images

Grunt: what is the purpose of cwd?

I know cwd stands for "current working directory", but what I don't understand is why is has to be included in the gruntfile.js.
Won't the script run always in the current working directory? Why would you need to change or specify another one?
grunt.js resides in the root of our project.
cwd is the path where grunt looks for the files matching the pattern in src and performs operations on. It can be an img folder in the current project root or a script folder in the current project root.
In other words, cwd is the parent folder of src files. It might not be the root folder of the root of the current project but a child of it.
Hope this helps answer your question.

How to change the path before injection

Is it possible to change the path of the injected file before injection occurs?
I am using Grunt/Bower/Connect/Wiredep, and my directory structure is:
www
|- dev-dist/
|- node_modules/
|- src/
|- vendor/
|- bower.json
|- Gruntfile.js
|- package.json
(Note: in my .bowerrc file I've added directory: vendor)
When I run the custom task grunt serve:dev it will create the directory dev-dist, I will then copy my index.html (only) to the folder, after which I run the task wiredep.
After running wiredep, the src paths to my dependencies are all prefixed with '../vendor/'. The problem is that when I run connect I have the option base: ['vendor', 'dev-dist', 'src']. When everything is served, the relative path to vendor doesn't make any sense because the vendor dir is already served at the root.
Is there a way I can modify the path to the injected files before wiredep injects them? (So I can remove the '../vendor')
What I would like to have happen is from the same workspace be able to run grunt serve:* and specify dev/stage/prod environments. This is why I did not want to serve the whole www directory.
Is there a way to exclude folders from being served in connect? (So instead of specifying base:[...], I can just exclude the stage-dist / prod-dist folders)
Thanks,
JD
You can use the option ignorePath with a regular expression
ignorePath: /\.\.\//,
from the wiredep to remove the ../ from the path that is getting injected. The configuration details are available over here https://github.com/taptapship/wiredep#configuration
I haven't used connect yet, so I am not sure of your second part of the question.

Resources