jaystack / jaydata

Notice: this library isn't maintained anymore
http://jaydata.org
GNU General Public License v2.0
352 stars 94 forks source link

webpack example needed #271

Open fberlin opened 8 years ago

fberlin commented 8 years ago

I'm having a hard time getting JayData working in a Angular2-application using Webpack as module loader.

Is there an example available of how to set up JayData with Webpack?

satlom commented 8 years ago

+1

bstaley commented 8 years ago

@robesz @lazarv This would be great to have. Any update on this?

Dynalon commented 8 years ago

This would be very important. I've tried for hours to get Jaydata + Webpack work with no success. Since webpack is currently pretty much the only supported (or at least somewhat documented) way for bundled angular2 applications, Jaydata currently prevents me from shipping a release version of the application. The development version using SystemJS is working, however. But we can't ship with a full node_modules folder in a release build, so webpack is currently the only solution.

PeterAronZentai commented 8 years ago

@lazarv ^^ Sorry guys for not earlier - but we pick this up today.

lazarv commented 8 years ago

Sorry for being so late with the webpack support fix, please update JayData to latest version from npm (1.5.10).

You have to include the json-loader in the webpack config file.

A simple example webpack.config.js:

var webpack = require("webpack");

module.exports = {
    entry: "./index.js",
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        preLoaders: [
            { test: /\.json$/, loader: "json" }
        ]
    },
    plugins: [
        new webpack.optimize.UglifyJsPlugin({ minimize: true, compress: { warnings: false } }),
        new webpack.optimize.OccurrenceOrderPlugin()
    ]
};
Dynalon commented 8 years ago

I added the json-loader (I had it in my project for other libs) but still there are problems with webpack: Main cause is that under webpack, Jaydata will require('jaydata/core') in my Context.js generated by jaysvcutiland at runtime will lazily try to load storage providers (odata, sqlite). But the lazy loading fails as the load location does not exist in a webpack bundle (i get 404 to /jaydataproviders/oDataProvider.min.js). There should be some way to hard-include the storage providers with webpack and lazy loading must follow commonjs and/or AMD semantics.

Edit/Note: Now that I think of it, lazy (async) loading is not supported in CommonJS modules (and thus not in webpack). Currently, jaydata tries to load the storage provider (i.e. odata) once factory() is called with a { provider: 'odata' } argument. This lazy-loading code has to be changed for CommonJS/Webpack envs, as CommonJS does not allow to load modules asynchronously at all.

lazarv commented 8 years ago

Just require("jaydata/odata"); (or import "jaydata/odata"; in TypeScript) before you import your generated context.