jedwards1211 / meteor-imports-webpack-plugin

Webpack plugin to import and use Meteor packages like if they were real NPM packages.
MIT License
25 stars 10 forks source link

Clarifications #1

Open lucidprogrammer opened 8 years ago

lucidprogrammer commented 8 years ago

Interesting project @luisherranz

If i understand correctly, I run the meteor (for server code) and webpack for client code during development. How do I do the meteor build for production with this approach, any inputs?

I gave a try with the example in es2015-meteor1.3-react

After the following change, it does the build without errors. ` var MeteorImportsPlugin = require('meteor-imports-webpack-plugin');

module.exports = { entry: './client/entry.jsx', output: { path: './build', filename: 'bundle.js' }, module: { loaders: [{ test: /.jsx?$/, loader: 'babel', query: { presets:['es2015', 'react'] } }] }, plugins: [ new MeteorImportsPlugin({ ROOT_URL: 'http://localhost:3000/', DDP_DEFAULT_CONNECTION_URL: 'http://localhost:3000/', PUBLIC_SETTINGS: {}, meteorFolder: 'server', meteorEnv: {}, exclude: ['ecmascript'] }) ] };

` However, no joy visiting localhost:8080(http://localhost:8080/bundle.js does show the js file ) bundle.js:7417 Uncaught ReferenceError: meteor_runtime_config is not defined

FYI ` in bundle.js /* 77 / /**/ function(module, exports) {

module.exports = {"ROOT_URL":"http://localhost:3000/","DDP_DEFAULT_CONNECTION_URL":"http://localhost:3000/","PUBLIC_SETTINGS":{},"meteorFolder":"server","meteorEnv":{},"exclude":["autoupdate","global-imports","hot-code-push","reload","ecmascript","ecmascript"]}

/***/ },

and the offending part is var config = webpack_require(77);

__meteor_runtime_config__ = config;

` (Anyway if you define with a var to meteor_runtime_config = config; this will go away. However, additional issues like bundle.js:32275 Uncaught TypeError: Cannot read property '_' of undefined (root =this, so not defined etc. ) This is a promising project and could be really useful to many. Could you check this example with 1.3-react with the latest METEOR@1.3.2.4 and see if this package be updated with the necessary fixes. It can be great and well appreciated. Tks

reohjs commented 8 years ago

@lucidprogrammer Did you manage to fix these?

luisherranz commented 8 years ago

@lucidprogrammer Sorry for the delay on this one. I missed it somehow.

Meteor build should be used only for the server. For the client, use webpack instead.

Does that solve your question?

reohjs commented 8 years ago

@luisherranz The __meteor_runtime_config error is coming from the client (webpack) on this line because it hasn't been defined yet

This also happens in the es2015-meteor1.3 example

I think @lucidprogrammer wanted to have a single meteor app including the client bundle for which my approach would be:

cd dev-app/client
webpack // this outputs the bundle.js file to the build/ directory
cd path/for/production
meteor create production-app
// copy the client bundle into a client/ folder
// copy the server files into a server/ folder
meteor build
luisherranz commented 8 years ago

I think @lucidprogrammer wanted to have a single meteor app including the client bundle.

If you want to be able to use meteor build for the client, maybe this project is a better fit: https://github.com/thereactivestack/meteor-webpack/tree/master/packages/webpack/

@luisherranz The __meteor_runtime_config error is coming from the client (webpack) on this line because it hasn't been defined yet

I see. It looks like it doesn't like that global declaration. Could you please check if this works?

window.__meteor_runtime_config__ = config;
lucidprogrammer commented 8 years ago

This was long ago. This is what i ended with

https://github.com/lucidprogrammer/mantra-sample-blog-app

reohjs commented 8 years ago

@luisherranz That fixes it, yes

lucidprogrammer commented 8 years ago

Refer to this, it fixes. This the one i used in that sample https://github.com/lucidprogrammer/meteor-imports-webpack-plugin

luisherranz commented 8 years ago

@luisherranz That fixes it, yes

Great! I'm leaving right now but I will upload a fix on Monday.

luisherranz commented 8 years ago

@lucidprogrammer that's so cool. I am glad this is useful for somebody! (as I am not using it myself).

Would you consider making a PR with your modifications so anybody can benefit?

lucidprogrammer commented 8 years ago

Yes will do

lucidprogrammer commented 8 years ago

Will do in the weekend. Tks

luisherranz commented 8 years ago

I have fixed the __meteor_runtime_config__ problem and published a new version to npm.