I make ember project from this guide . But i have something like default application - routes and etc . How can i delete this and start from scratch ?
This guide is how to start ember using ember-cli. I am sure this is the main road to build ember apps. Ember-cli has conventional directory-files structure, you could see it when you run ember new my-app-name. For example all routes are in the app/routes directory and etc. You may delete all files/directories you don't need, but all files you use (or ember-cli uses) must be in the conventional directory.
As far as I understand, you'd like to begin with something simpler. You can start with simple html file, using any default jsbin you like, for example http://emberjs.jsbin.com/?html,css,js,output
Community usually use such jsbins for demonstrating issues. See jsbins collection here https://gist.github.com/rwjblue/8816372
Related
I'm building a Node and React app, both using TypeScript. Its directories tree is as follows:
My question:
Since I'm using the same language for both stacks, and in the future the React Native will be added also using TypeScript, I wonder how I can create one group of classes to be used for all of them.
Why I want to do this:
DRY (Don't repeat yourself): My intention is to take full advantage of using the same programming language in all layers so there's no sense creating two equal classes.
What I have tried so far:
I created a third folder called "util" and put a generic class just to test both Node and React using it. Like this:
In Node.js I used the command below to import it:
import Person from "../../util/person.class";
And in React.js, I used the same logic to import it:
import Person from "../../util/person.class";
As I already expected, both deny using files that are outside their respective root folders:
I also searched in the internet about this and I found some "eject" command that, once used, there's no way back, whatever. I'd like to avoid such ways. Is there any approach where I could take in my favor?
I also want to mention that I created a tsconfig.json for backend using "tsc --init" and set the rootDir as "./src/" and outputDir as "./dist/".
Thanks.
You could set up a third project that has the shared functionality. Then you can publish the shared package to a npm repository. And then you can install the shared package in the frontend and backend project.
If you want to send the react from the sever then the front-end files should be under the back-end folder
/app root
/ back-end
/shared-front-end-classes
/front-end-desktop
/front-end-mobile
Though this is not the best solution
The best solution is to host the front-end on a different server and make the
back-end totally functional with APIs
For example :
I have a blog that I host the
Front-end:
Github pages "Support react via a small npm package"
Back-end:
Hosted on Heroku
DB:
I am using mongoAtlas "A cloud DB"
now you have 3 separate places to hold all of your code independent of each other
Now for your other problem, you want to use the same classes over the two front-ends
For me, I usually make a small repo with all the components/ pages that I want then import this in any project for future use
I am not sure if this follows the DRY concept but you will not write your code twice
As in many SaaS application we provide admins to add custom HTML, CSS and JS directly from any backend form. It works perfectly in applications built without any JS framework like react or vue.
I want to do the same with react application.
The solution that I am thinking can be-
Add the custom code to bundle.js after compiling. We can use gulp or webpack to compile the code or something to apply those changes to the production build of react application.
Is it possible to add the code in the public/index.js directly when the code is in production
I may be wrong. Please suggest me any possible way to make things in production react application.
I really can't say anything about q1. But for q2 it is not a good option to add code in index.js file even if it runs locally. It is not a good practice to write all your code in index.js or App.js. Trying to make components and write cleaner code is the beauty of React.
I have started to learn react and I am very confused with the concept of packages.
and why we can't just use a simple link as cdn and there is a module which i don't understand it and what's npm and why i have to use it with react
Not trying to give the definite answer here, but trying to explain the 3 terms as simple as I can:
A module is just a file containing lines of JavaScript code.
A library uses one or many modules to provide a set of features.
A package is a downloadable, versioned library. Think of someone putting it in a box and shipping it to you, so you can import it and use it in combination with your own code.
so I came with conclusion and hope you tell me if I get it right or not .
-Module : it is justba javascript file but it's different from normal script that it has its own scope so you have to use import or export to exchange information between modules.
-Library : it is a group of modules or scripts that it is responsible for the function you want .
-package : can be one or more libraries but it is also contain files that don't deal with the functionality but it's only role to make sure the libraries and functional file work properly .
like react package it is come with react library deals with the functionality and also has babel compiler to make browser read and understand react library.
It is very much possible to use a simple link such as a CDN. Many packages also have links available, such as material UI. However, it quickly becomes unmanageable to use CDN links when your project grows, and it can affect performance and load times of your site.
Npm stands for Node package manager. It handles packaging for Node, where it would not be suitable to use a simple link.
It turns out that it is possible to also use npm for web applications, by combining it with a bundler. The bundler (such as webpack) takes all of your modules (JavaScript files and npm packages) and bundles it together so that you get a single script which you can run in the browser.
I have a production application whose folder structure is much like you would expect:
/project
/css
/js
/php
/fonts
/images
/index.php
I have recently begun learning to use react.js and I would like to start developing new features using react while leaving all existing functionality as is and I understand that react.js can certainly be used this way.
What isn't entirely clear, is how to structure the files in my non node.js project and access them.
For example, I tried searching for this and found this article which proposes the following structure
and states:
Here index.jsx works as the entry point of the application. It uses ReactDOM.render to render App and gets the party started. App in turn does something interesting with Note. If I wanted yet another component, you would simply add it below /components.
Presumably this is a node.js project where index.jsx can call something like require('components/App.jsx');, but how do I achieve the same in my non node.js project.
Consider if I set the following folder structure:
/project
/css
/js
/php
/fonts
/images
/react
/components
/App.jsx
/Note.jsx
/scripts
/featureFoo.jsx
/index.php
Given the above, I'd like to have index.php load react/scripts/featureFoo.jsx which would somehow include/use react/components/App.jsx and react/components/Note.jsx
I figure I could have script tags in index.php to load all of the components then featureFoo.jsx but I feel like there is a more react way to do this.
So
How can I structure/access the react components of my non node.js application?
Im tagging node.js as I feel those users may well bring insight regarding this possibly from having to deal with multiple projects/aproaches.
In order to import/require other modules in a non-node.js (i.e. browser-based) JS application, you'll need to use a bundler such as webpack or browserify.
They work by starting at your "entry" file (index.jsx in your case) and recursively following all of your imports/requires. Then it smartly bundles everything up into a single "output" file, which includes everything your application uses, that you can link in your HTML.
You can also use more complex configurations with multiple entry and output files, or even dynamic loading of "chunks" at certain points in your application. But the above is the most basic use case, and works well for most simpler projects.
These bundlers have some other cool features as well. For instance, with webpack (with additional plugins and loaders) you can:
Write ES6/ES7 JavaScript that gets compiled (via babel) into cross-browser compatible ES5
minify/uglify your output JS
import/require non-js files such as CSS, images, and webfonts, and choose how to process these imports (e.g. pre/post-process your CSS, or optimize your images)
Extract all imported CSS into a single .css file
Use webpack-dev-server (or webpack-dev-middleware) to take advantage of hot module replacement, which makes developing JS apps easier by letting you see your changes take effect instantly in the browser without having to refresh or lose your app's state.
And a lot more. The world of bundlers is a pretty big ecosystem with a lot to learn, but it's totally worth getting into.
A good place to get started is the excellent Survive JS series of tutorials.
However, if you're still learning React, then diving into webpack and the entire ecosystem of JavaScript tooling can be overwhelming. It will probably be easier and a more efficient use of your time to keep things simple at first, and then only get into bundlers etc. after you get comfortable with React.
I have been messing around with embejs and I have been using default index.html with script tags to render templates on the page, sufice to say my index.html file is littered with:
<script type="text/x-handlebars" data-template-name="aisis">
</script>
That I would like to split up. Now I have worked with ember a little bit in rails applications, but this app doesn't have a back end, doesn't use anything other then javascript and html as its a simple internal app.
My question is, how do I split this up into partials and various other templates and still keep the app nice and small, nice and simple? I have seen a bunch of ember tools out there that generate or scaffold projects for you, but I get lost and confused fast. Where as the way I have been doing it has taught me a lot, it's just my project is massive in one index file...
Ember is designed so that each route should correspond against a template. Whenever you enter a new route, a corresponding template will automatically be rendered unless you override the "renderTemplate" hook.
Try going through the "getting started" guide here: http://emberjs.com/guides/
I would recommend looking at the yeoman suite of tools: http://yeoman.io/
It includes an Ember generator that will scaffold your project, create your bower dependencies, generate a grunt file for builds, etc. Install generator-ember to get started with the scaffolding.
Just create an empty folder, and from there use yo ember to get a complete working app. Take a look at what is generated and you can get some ideas of what to incorporate in your app.
I would check out Ember App Kit. It lets you break up the templates into various files in addition to automatically importing correct modules, linting your code and providing various build options.
Ember App Kit (EAK) is a robust starter kit for developing
applications in Ember.js. EAK makes it easy to develop, build, test,
and deploy applications independent of any back-end build process.