Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to require css file using NPM and Meteor?

I want to add the react-date-picker (https://github.com/zippyui/react-date-picker). It says that I need to add the lines

require('react-date-picker/index.css');
var DatePicker = require('react-date-picker');

And using meteorhacks:npm and browserify, I have the module working.

/server/declarations.js

DatePicker = Meteor.npmRequire('react-date-picker');

/lib/app.browserify.js

DatePicker = require('react-date-picker');

But how can I get the CSS file that styles the module to work? I don't know where to put the require('react-date-picker/index.css') without throwing a syntax error. And I can't assign it to a variable, so what do I do?

like image 871
theswooner Avatar asked Jan 01 '16 03:01

theswooner


People also ask

How use NPM package meteor?

To use an npm package from a file in your application you import the name of the package: import moment from 'moment'; // this is equivalent to the standard node require: const moment = require('moment'); This imports the default export from the package into the symbol moment .

What does meteor build do?

What does it do? The Meteor build tool is what compiles, runs, deploys, and publishes all of your Meteor apps and packages. It's Meteor's built-in solution to the problems also solved by tools like Grunt, Gulp, Webpack, Browserify, Nodemon, and many others, and uses many popular Node.

Does npm install install everything in Package JSON?

By default, npm install will install all modules listed as dependencies in package. json .

What is Npmjs?

npm is two things: first and foremost, it is an online repository for the publishing of open-source Node. js projects; second, it is a command-line utility for interacting with said repository that aids in package installation, version management, and dependency management.


1 Answers

When Meteor 1.3.2 comes out, you will be able to do, in foo.js:

import "npm-package-name/path/to/style.css";

If you are < 1.3.2, the workaround is to create a package in packages/my-asset-imports like this:

https://gist.github.com/BretFisher/9ea1ba440cb999af9c95

like image 172
Loren Avatar answered Oct 05 '22 23:10

Loren