I am developing a rails app. It has javascript functionality in app/assets/javascript. Now I have multiple javascript files. I want to use method from one javascript file in another file.
I tried export, import concept.
My doubt is what should be the path in import? cause I am running this app in local environment.
if my path is this
"/home/manoharsinhrana/workspace/copy/housing.ads.service/app/assets/javascripts/ad_products/utility.js it "
It would not work in production.
Related
For my current project, I'm developing a frontend application that consumes a backend API. I would like to keep the URL of the backend dynamic (e.g. in a seperate config file). However, with Webpack, all defined variables end up in a bundle, which makes it hard to keep the backend URL dynamic (I'd have to dive in the bundle and change the URL).
How would I achieve this using Webpack 2? Basically I want to import a config file that gets excluded from the bundle so I can easily modify the config file later on.
My current solution is to define a window.config object in my index.html and read the window object from my application. I feel there should be a better way to achieve this though.
I am working on a project using AngularJS and NodeJS. I am new to both frameworks and need some help for reading in (text) files.
I am trying to read files using npm's read-file (https://www.npmjs.com/package/read-file).
I put var read = require('read-file') into one of my controllers Javascript files, but I keep getting an error message Cannot find module 'read-file'
Below is the current project structure:
my_project
|--app
|--bower_components
|--components
|--scripts
|--controllers
|--my_controller.js
|--styles
|--views
|--my_page.html
|--app.js
|--index.html
|--node_modules
|--read-file
|--index.js
|--LICENSE
|--package.json
|--README.md
Clearly I installed the read-file module, but I think there is an issue locating it. What should I do to make sure that require('read-file') correctly locates the read-file module?
Any help will be appreciated. Thanks!
It seems that you are trying to read the read-file module within your Angular.js application controller. The controllers within Angular.js are front end files and are run from within the Browser environment and not Node.js. Therefore, you cannot use utilities such as require within the browser.
I think you may be able to achieve what you are trying to accomplish by running your front end application through a tool like Browserify. This will allow you to use Node.js to do stuff like require which will load the file during compilation time and allow you to require files within the browser. You can also use Node.js tools such as fs to load the contents of files and include them within your front end application. I think this should get you pretty close.
I think you are trying to load the read-file module in the client js part, where is not defined at all.
You should create your node server here, and create an api you should call from your front-end controller that load get the file.
From the node api handler you read the file and send back to the client when requested.
I am using meteor, which I am new to, for my current project and want to replace the current chessboard I made with that from chessboardjs.com and was hoping some one may have experience with this. I downloaded the files from the website, put the css files in a css directory I created and the images in my public/image directory but was wondering where to place the .js files. I am not used to working with multiple files in meteor. I am creating a client and server directory. Should I just place the .js files in the client directory? Also, on the site it says to get started add
to the javascript
var board1 = new ChessBoard('board1', 'start');
and to the html
Could some one suggest a way to use meteor templates to put this in the .js files? I am a bit confused.
You should place external client libraries somewhere in /client folder. Usually it's either /client/lib to ensure they're loaded before the rest of your code, or /client/compatibility to ensure they work even if they aren't designed to work with Meteor, or /client/lib/compatibility for both.
I want to write coffeescript that would read a file at compile time and produce a javascript file that initializes a variable with the file contents.
My app has a bunch of error messages and stubs that need to be maintained independently by copy editors and such. But all of them need to be inline in the js that is served to the client browser.
Are there 'pre-processor' directives that will let me do this?
Javasccript in and of itself doesn't have this capability. So what you are trying to do is not a good practice. The variables that you are trying to change on compile time, keep them in a separate javascript file. Then while building your project, initialize those variables in the separate file and concat them to serve (possibly minified) javascript file. There are tools available to do this. Check out uglify and grunt
I am using the modular folder structure shown here by tjholowaychuk.
Is it somehow possible to also have a separate client JS in each of these modules? Currently all my client JS is in the /assets/js folder, but it would be nice to have a JS file in the module instead.
After playing around with it, the best solution for me seems to be to put the client js under lib/module/client/, and then just use this path in the script tag. This way I can have a client js file for each module.