jaydata icon indicating copy to clipboard operation
jaydata copied to clipboard

webpack example needed

Open fberlin opened this issue 9 years ago • 7 comments

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?

fberlin avatar Sep 19 '16 13:09 fberlin

+1

satlom avatar Sep 20 '16 05:09 satlom

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

bstaley avatar Nov 07 '16 21:11 bstaley

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.

Dynalon avatar Nov 08 '16 12:11 Dynalon

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

PeterAronZentai avatar Nov 08 '16 13:11 PeterAronZentai

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()
    ]
};

lazarv avatar Nov 09 '16 10:11 lazarv

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.

Dynalon avatar Nov 09 '16 10:11 Dynalon

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

lazarv avatar Nov 09 '16 15:11 lazarv