I am attempting to use yeoman to scafold a web site, my website includes references to files such as images/foo.kml
Running Grunt results in these files being filerev, i.e. the file images/foo.kml is copied to the dist directory but now called images/3333.foo.kml.
The only problem is that usermin task does not replace the references to images/foo.kml in the requested javascript file, but it does manage to process all the references to css and javascript files.
References to images, css and javascript files are normally listed by html tags, eg , etc. In my case I am making a programmtic request to a kml file which is used by a bit of add hock javascript, can usermin deal with type of problem? Or would I be better off putting all of the files that are going to be accessed by a javascript application in a different directory and ensure that references to these files are not subject to filerev?
Bottom line I was using OpenLayers to process the kml files, as the files are not used my img tags and only by a Java script program, the file name has to remain a constant. Since the uglify task has no concept of understanding a file name within a block of Javascript.
My solution was to change the grunt file so that my kml files are copied from the app to the dist directory.
Related
I'm currently using Meteor and trying to learn more about the framework. In the documentation about special directories the following is said about the public/ special directory:
All files inside a top-level directory called public/ are served as-is to the client. When referencing these assets, do not include public/ in the URL, write the URL as if they were all in the top level. For example, reference public/bg.png as <img src='/bg.png' />. This is the best place for favicon.ico, robots.txt, and similar files.
My question is: since I refer to files inside of public/ directory as if they were located in the root folder of my application, what's the different between putting the files in the public/ folder and in the root folder? Or is it just for organization sake?
Also the documentation I quoted above makes some examples using assets (some pngs and favicon.ico) and no JavaScript or HTML files. Am I able to put some JavaScript code in there and then import them in another file by referencing as if this code was located in the root of my app? Or is the public/ directory somewhat made only for assets?
I failed to find any docs that explains what is done to files inside this directory in detail (I only found what I quoted above). So if any documentation of that kind is available it would help a lot!
My question is: since I refer to files inside of public/ directory as if they were located in the root folder of my application, what's the different between putting the files in the public/ folder and in the root folder? Or is it just for organization sake?
Just because you can reference or "import" a file from public/ doesn't mean it functions in the same way to how a normal file import would work. Files located in public gets served as is without being minified/run through the Meteor pipleline. Second, these files are accessible to the client which makes sense given how'd import them without preceding slashes and keep them mostly to serve stuff like favicon and what not.
So in a sense, such files within public are made available within relation to your client bundle/code whilst not being a part of them, get it?
This way of serving assets isn't unique to Meteor, even React has a public directory.
Also the documentation I quoted above makes some examples using assets (some pngs and favicon.ico) and no JavaScript or HTML files. Am I able to put some JavaScript code in there and then import them in another file by referencing as if this code was located in the root of my app? Or is the public/ directory somewhat made only for assets?
AFAIK, you can have files of any type in public but since
It's served as is to the client, meaning it's exposed to the public
It doesn't get minified (i.e being part of the final application build code)
You're advised to not have any of the application code within this directory.
The Public folder is how you serve your static files, when you put a file in your root folder it will not be sent to the client by default and you can't use it in your css, when you put that file (say an image) in your public folder you can use it from the css and refer to it as if it was in your root folder, so if I put a.jpg in the public folder I can use url(/a.jpg) in my css, that won't work if a.jpg is simply in your root folder, that's what the docs mean when they say it's served as if it was the root folder.
unlike in Rails, Meteor initiatives don’t have a rigid document structure and you are quite a whole lot free to prepare your projects as you want. a few folder names but have unique which means, and documents within them will be dealt with in a different way.
consumer
files here will be loaded at the client simplest. files in that folder don’t need things like Meteor.isClient.
server
Loaded on the server best, duh! No need for Meteor.isServer whilst files are in that folder, the client won’t see these files.
public
This directory is for property like photographs. on your initiatives, you reference stuff in the public folder as if they have been in the root folder. as an example, when you have a report: public/nude.jpg, then for your app you include it with .
personal
files only available at the server facet thru the assets API.
checks
documents in there received’t be loaded anywhere and are used for checking out your app.
lib
documents in that folder are loaded earlier than whatever else, which makes it the best listing to vicinity the distinct libraries used on a undertaking.
The following question was rewritten, because I have now a working solution, but no answer to the question above.
The repository that shows different scenarios how to use resources packed with webpack is named example-webpack-dynamic-resources. It contains 3 modules:
inline: a solution, but not useful in my context (many resource files)
file: a solution by using the plugin webpack-require-from
public-path: no solution yet, shows how I would like to use __webpack?public_path__.
I think I have read any resource about webpack and publicPath and __webpack_public_path__, but I don't get it to work. I try to dynamically change the path to static resources, but it fails.
Here is my context:
I build a Javascript library that will be used on web pages (HTML, CSS, Javascript).
It provides a lot (>100) static resources to small image files, combined > 500 KB. Only a fraction of it will be used by the user looking at the web site.
Therefore I would like to pack the CSS into the bundle, but keep the image resources in a directory located on the server somewhere. The default path to it will be /img.
As long as I use the same structure (which means, images only under ROOT/img/**, everything is ok.
But the users of the library should be able to configure the path to the image resources on their will.
You will find all relevant files in my example repository example-webpack-dynamic-resources in the module public-path-resources.
webpack.js: Use file-loader for images, which are referenced in CSS files. CSS will be inlined by style-loader and css-loader.
src/public-path.js: Define the global variable with a default (no environment variable).
src/index.js: require first public-path, then the logic.
examples/exam1-root/index.html: Tries to use the assets in the sub directory lib, sets the value therefore to __webpack_public_path__ = '/lib/. Not working.
examples/exam2-different-dirs/index.html: Moves the library to a different dir (not relevant), but uses the originally defined directory pgnv-assets for the assets. Working.
examples/exam3-non-standard-dirs/index.html: Try to use instead my-assets as directory for the assets. Not working.
How could the __webpack_public_path__ defined at runtime in the index.html file?
I'm fairly new to webpack.
From a YouTube tutorial (Academind) I watched, the guy teaches the user to include the HTML file in the entry .js file. From what I understand, webpack will then use HtmlWebpackPlugin to extract the required HTML file out, then inject either as a file or code into that HTML file. Is my understanding correct?
I'd like the above question answered, but that's not the main question. The main question is the reason for going through such pain.
Can't I just have the .html files copied to /dist and have each .html file have bundle1.js, bundle2.js, etc., in them?
That tutorial required html file because it was thought that it was easier to let webpack (HtmlWebpackPlugin) insert all the script tags for the bundles automatically, without having to do that manually.
You can also not require that, and add the template property on HtmlWebpackPlugin. That will do the same thing.
You can also copy to dist, of course. But that would require you to insert manually script tags on your html. That starts to get worst when you have hashes on your filenames.
I'm writing a tornado web app and have a file named "static" with files such as main.js, require.js, elasticsearch.js, and d3.v3.js. The last three are just source code for the javascript libraries.
In my index.html file I have the lines
<script>src={{ static_url("scripts/require.js") }}></script>
<script>require([{{ static_url("scripts/main.js") }}], function () {})</script>
Now when I run the app, I get two errors:
ERROR:tornado.general:Could not open static file '...'
for each of my two files that I'm reading in. Has anyone ever had a similar issue or have any insights as to why this is happening?
Are the js files directly in the static directory or in a scripts subdirectory? Assuming you did something like static_path="static" when creating the application, the files need to live in static/scripts/*.js to match the paths you use in your static_url call.
With smart gwt 4 when I run the application I get the following error
Core SmartClient JavaScript libraries appear not to be loaded.
If inheriting the NoScript SmartGWT modules, verify that the HTML file includes tags to load the SmartClient module .js files from the appropriate location within the WAR.
By default these files are present under [GWT app name]/sc/modules/.
com.smartgwt.client.core.JsObject$SGWT_WARN: Core SmartClient JavaScript libraries appear not to be loaded.
If inheriting the NoScript SmartGWT modules, verify that the HTML file includes tags to load the SmartClient module .js files from the appropriate location within the WAR.
By default these files are present under [GWT app name]/sc/modules/.
I have set the following jar in my classpath
smartgwt.jar
smartgw-skin.jar
and add the inhert in my .gwt.xml file
And in my jps file i add the script
Thanks in advance
Make sure all of the paths are correct and the files are there in your WAR. It's also important to understand how the GWT directory structure works inside WAR files (the relative paths are not always what you think they should be).
Have you tried using GWT.getModuleBaseURL() or GWT.getHostPageBaseURL() for your paths?
Check these other posts for more info:
Path for images folder in GWT project
https://groups.google.com/forum/#!topic/google-web-toolkit/PxdjqjMIlVY