Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

webpack example needed #271

Open
fberlin opened this issue Sep 19, 2016 · 7 comments
Open

webpack example needed #271

fberlin opened this issue Sep 19, 2016 · 7 comments
Assignees

Comments

@fberlin
Copy link

fberlin commented Sep 19, 2016

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
Copy link

satlom commented Sep 20, 2016

+1

@bstaley
Copy link

bstaley commented Nov 7, 2016

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

@Dynalon
Copy link

Dynalon commented Nov 8, 2016

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
Copy link
Contributor

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

lazarv added a commit that referenced this issue Nov 9, 2016
@lazarv
Copy link
Collaborator

lazarv commented Nov 9, 2016

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
Copy link

Dynalon commented Nov 9, 2016

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
Copy link
Collaborator

lazarv commented Nov 9, 2016

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants