Extract raw CSS/SCSS file and use output in JS - javascript

I'm making simple components library. Basic project setup based on Webpack.
I've got all my components in separate folders with structure like below.
test/
|- test.html
|- test.scss
|- test.md
I'm loading HTML files in my app.js as string and creating previews and code snippets, but I can't load my SCSS files as raw content.
Here is the CodeSandox link with my project setup: preview link
What I need?
I need my .scss files content available in app.js as text, so I'll be able to generate snippets in code blocks available for a user.
I don't need help with compilation, it's all good there.
Thanks!

Related

Flask js files not loading due to template folder and static folder file structure

So I'm trying to make a website where I'm able to just drag and drop folders containing HTML, js, and CSS files into a "library" directory and have those files served on my flask app. There's one big problem I haven't been able to get over. The problem is that all of these HTML files link to their respective js files using relative paths. For example:
<script src="js/keyboard_input_manager.js"></script>
and these files are 2 folders deep into my (combined) templates/static folder. I could fix this by doing
<script src="library/2048/js/keyboard_input_manager.js"></script>
but that is very tedious, especially when working with so many files.
TLDR: If I were to run my flask app and load a template, it wouldn't load any js or CSS because of relative paths.
Is there any way to go about this without individually changing each path to relate to the templates folder?
Example of my current filesystem:
-FLASK PROJECT
|->library (templates/static folder)
| |->2048
| |->index.html, index.css, index.js
| |->Game2
| |->index.html, index.css, index.js
|->main.py
What I've Tried:
Using Blueprint but I can't create a whole blueprint for every file?
Messing with paths of template folder and static folder
Flask Noob - Please let me know if I'm leaving out any helpful information :) Thanks

ASP.NET Core + React | Correct way to structure files

What is the correct way to structure files in real life application?
By default, if I'm correct, ASP.NET Core projects files should be structured as:
[Solution]
[Project]
Dependencies
Properties
Controllers
Models
Repositories
wwwroot
Pages
Startup.cs
Program.cs
appsettings.json
For any static file it should be inside a wwwroot folder, right?
But then why creating a ASP.NET Core project with React + redux template makes a folder 'ClientApp' instead of 'wwwroot' and places all react code in there with folders 'src' 'public'?
I know that you can do that and then in startup.cs enable it with 'app.UseSpaStaticFiles();', But why? Is it just to make it simpler or does it have real life benefits? Should I structure my files same way too?
And if I suppose, or can, use with 'wwwroot', how should wwwroot folder look? I know that wwwroot folder suppose to contain all the static files such as css, images and js
wwwroot
css
js
images
Since react is a js library/framework, should all code be inside js folder like this
wwwroot
css
js
src
actions
components
store
...
images
I been trying to find an answer but everywhere everyone has a different answer.
On a side note, also if using scss, or similar, should all the scss be inside css folder or should there be a scss folder inside wwwroot that on compile saves css code inside css folder?

angular 4 project with custom html theme

I am trying to create a angular 4 project from angular cli and I am trying to import a custom html theme.Theme has and css files js files and some font files. Where put all those files?? in asset folder?? And after that I will import them in index.html as script and links? With that way I am getting some errors "can't resolve the dependencies" like fonts.Exist other way more efficient and "more right" for the angular standards like through angular-cli.json or something else??
I have searched everywhere how I do this but no luck.
Firstly generate new component and you can use this component to design your own template and to add own CSS
as follow:-
firstly generate new component ng g component mycomponent
new component will be created like below :-
mycomponent
mytest.component.css
mytest.component.html
mytest.component.spec.ts
mytest.component.ts
then you can add your styles at .CSS file, your all template at .html file and all logical content at .ts file
you can add this component at index.html
<app-mycomponent></app-mycomponent> // app-yourcomponent name
when you create the project i wonder you have a src folder. Inside this folder you have an assets folder: here you can paste all the code and images from your html code.
Next, you have these options:
Import the static files of your html theme one by one on the index.html in this way:
and so on..
In your angular-cli.json file:
"scripts": ["../src/assets/js/jquery.min.js"],
and so on with all your code scripts. The css styles have a styles array in the same angular-cli.json file.
Last but not least, if your html theme have images and other static content incorporated, you can access all this content in this way:
<img src="../src/assets/images/logo.png" alt=""></a>
so, you access the local folder of any file with ../ and if you want to access a superior folder you can use ../../ and so on until you get in the root folder.

Unable to find bower_components in the directory above

I have the following directory structure in one of my projects:
/web
/bower_components
/bootstrap
/jquery
/typeahead.js
/views
/index.jade
I'm trying to use these components from my index.jade file in the following way:
link(src='../bower_components/bootstrap/dist/css/bootstrap.min.css', rel='stylesheet')
script(src='../bower_components/jquery/dist/jquery.min.js')
script(src='../bower_components/typeahead.js/dist/typeahead.bundle.min.js')
but it doesn't work (there's no bootstrap-related styles on this page and jQuery code doesn't work).
Why? What am I doing wrong? How can I fix it?
Should I refer to these components in a different way?
Should I place bower_components directory in another folder?
You probably need to change the file path to be relative to where you are compiling the jade file to.
For example, if you render the jade like this:
/web
/index.html
the source paths would be
link(src='bower_components/bootstrap/dist/css/bootstrap.min.css', rel='stylesheet')
script(src='bower_components/jquery/dist/jquery.min.js')
script(src='bower_components/typeahead.js/dist/typeahead.bundle.min.js')

How to change path of welcome html file

I have created Dynamic web project and it has .html, .css and .js files. I group these file in respective folders like .js file in javascripts folder and .html file in views folder but i don't able to access these file in project. I used eclipse IDE for this. Is there need to configure path for these folder?
You need to put the JSP file in /index.jsp instead of in /WEB-INF/jsp/index.jsp. This way the whole servlet is superflous by the way.
WebContent
|-- META-INF
|-- WEB-INF
| -- web.xml
-- index.jsp
If you're absolutely positive that you need to invoke a servlet this strange way, then you should map it on an URL pattern of /index.jsp instead of /index. You only need to change it to get the request dispatcher from request instead of from config and get rid of the whole init() method.
These are not Java source files, so it makes no sense to configure them as such. By default in a Dynamic Web Project you only see the src folder under Java Resources. Other folders will be listed at the bottom of the tree. This is by design.
Or if you meant, that you do not see them when you move into the folder by an external file manager: press F5 on the project.
Its based on from which file you are trying to access those files.
If it is in the same folder where your working project file is, then you can use just the file name. no need of path.
If it is in the another folder which is under the same parent folder of your working project file then you can use location like in the following /javascript/sample.js
In your example if you are trying to access your js file from your html file you can use the following location
../javascript/sample.js
the prefix../ will go to the parent folder of the file(Folder upward journey)
I got answer to my question...
Now my directory structure is
WebContent
--javascripts
--stylesheets
--viwes
--META-INF
--WEB-INF
Note: view contain html files
To change path of my welcome html file i made bit change in web.xml present in WEB-INFfolder.
<welcome-file-list>
<welcome-file>/views/welcome.html</welcome-file>
</welcome-file-list>

Categories

Resources