meteor can't find global variable in node_modules - meteor

I want to use packages such as shelljs(https://atmospherejs.com/izzilab/shelljs) but I am getting an error, "can't find variable: shell". It is an npm package wrapped around for Meteor. Why wouldn't the variable be global scoped though?
Does anyone know what the best way to list all files in a local directory is within meteor client code?

if your project runs on the version of meteor 1.3 and you're writing everything in the imports folder, then you need to use export/import feature of es6 modules.

Related

Correct way to use external template in meteor mantra

I am learning Mantra style guide (https://kadirahq.github.io/mantra/) to use with meteor. What puzzles me is what is the "correct" way to use external template with meteor and mantra? in example css and js files. I know that in meteor one can create a package and load it.
But should one also do the same in meteor + mantra, i.e. create a package as https://github.com/kadirahq/mantra/issues/53 suggests? Will meteor then load all necessary files (css or js) correctly? Or is there a better way?
Best Regards
Mantra follows modular structure. Your code will be in the form of module doesn't matter its UI related or not. It will load things like meteor application but application will start from starting point you have defined.
Yes you can create a package and load it from there but when you have npm package in your hand which you can directly use in you modules, I think creating package will be a bad idea for that.
In the project with mantra I had worked, we used rebass. We had created some common components for UI purpose only and added them to a separate module and exported them from index.js. In every module we called components from that module and used it whenever required. Better way is to use npm packages so that you wont have to worry about loading JS.

Meteor App hangs when adding Ecmascript

I recently updated my Meteor App to 1.3 and also want to migrate to the "new style" of coding, meaning ES2015, React, later on Apollo/GraphQL.
First I only want to use the import syntax. But when I meteor add Ecmascript it will then hang on meteor:
Building for web.browser /
takes forever.
Any ideas why?
I had the same issue. In my case this is how I got it fixed. May be it is the same for you.
I had multiple third party libraries in client/lib folder.
To use ES6 syntax, I added 'ecmascript' to my .meteor/packages file and after that issuing the meteor command would just hang.
During trial and error, I figured out that
deleting the client/lib directory made meteor to start
.
For the libraries my application depends on, I went to https://atmospherejs.com, searched for the meteor specific package name for the dependency and added these to .meteor/packages file.
e.g: Instead of copying the datatables.js and datatables.css inside client/lib folder, add 'menway:jquery-datatables' to .meteor/packages or issue the command meteor add menway:jquery-datatables

how to make meteor ignore files in a Package?

I have a package which includes a file that gets frequently rebuilt. This causes meteor to restart each time that file is edited.
There are ways to get meteor to ignore files within the main app, eg putting inside a .directory but is there a way to do this within a package?
The catch is that I DO need the final file to be included for deployment, so it has to be named - as an asset - and included in the package addFiles.
The only solution I have so far is to host the asset external to the meteor app and load it in via http or something on each cold start, but that's a bit fragile.
As of Meteor v1.5.2.1, there is support for a .meteorignore file. It behaves the same as a .gitignore. Have you tried using it?
You can use them in any directory of your project and are fully integrated with the file watching system.

Meteor package file inclusion

I want to build a meteor package to wrap an existing javascript library. I would like to include the library as a git submodule. I only need 2 files from the submodule. If I only include these two in package.js will the rest of the files be ignored by meteor and not built into the package?
The only files that will end up in your package are those that will be explicitly added with api.addFiles routine (look here).
BTW, If you're planning to wrap an existing JavaScript library then you should probably start by getting familiar with autopublish project. For more details watch this video.

Exposing Sass file from Meteor package for Meteor App importing

I'm working on building a package for meteor 0.9+ that exposes a library off sass mixins called 'Bourbon' and am trying to sort out the best way to provide access to '#import' a stylesheet from the package into a Meteor project.
https://github.com/wolvesio/meteor-bourbon/
Pre Meteor 0.9 this used to be done via something along the lines of:
#import "packages/wolves:bourbon/bourbon";
Since the package system changed though this no longer works. Any help as to the best way to do this moving forward would be greatly appreciated.
I've managed to accomplish what you want, it's a bit hacky but it works at last.
First, you need to add the .less files as server assets in your package :
Package.onUse(function(api){
api.addFiles([
"bourbon/style1.less",
...
"bourbon/styleN.less"
],"server",{
isAsset:true
});
});
Then run meteor to trigger the building of your application : this will copy over the server assets to the .meteor directory of your application. More precisely, your .less files will now live in ".meteor/local/build/programs/server/assets/packages/wolves:bourbon/bourbon/*".
Now you can reference these .less files in your application using this super unfriendly path.
I recommend hiding this stuff from your package users by defining an import.less directly in the package :
packages/wolves:bourbon/bourbon.import.less
#bourbon-root: ".meteor/local/build/programs/server/assets/packages/wolves:bourbon/bourbon/";
#import "#{bourbon-root}style1.less";
//
#import "#{bourbon-root}styleN.less";
Then in the package README, invite your users to simply copy bourbon.import.less in their client directory and reference it from there.
client/lib/config/style.less
#import "bourbon.import.less";
There is one drawback to this approach that I was unable to solve at the moment : the .less files are copied in the .meteor directory when your application is built (a process that happens when triggering meteor run).
However, the build process will try to compile your application .less files FIRST, before copying the server assets (in this case our package .less files) to the .meteor dir.
So the very first time you add the package to an app, it will complain that it is unable to find the package .less files, triggering a rebuild (either by killing and relaunching meteor or touching your application .less files) will fix this though.

Resources