Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Won't initialize with webpack. #10

Closed
richardelloyd opened this issue May 23, 2016 · 10 comments
Closed

Won't initialize with webpack. #10

richardelloyd opened this issue May 23, 2016 · 10 comments

Comments

@richardelloyd
Copy link

richardelloyd commented May 23, 2016

I've been trying to find the sweet spot to require the js file but when I test on a device, The window object doesn't see cordovaSQLiteDriver loaded. Are there any webpack examples of this working?

Any thoughts?
Using:
localforage-cordovaSQLiteDriver v1.3.0
localforage v1.4.0
cordova-sqlite-storage v1.4.1

Thanks

@thgreasi
Copy link
Owner

To be honest I never tested it with CommonJS. Can you point me to a
boilerplate project that's similar with yours? I will probably reactor this
lib to use es6 with rollup as a way to solve this.

Thodoris Greasidis
Computer, Networking &
Communications Engineer

@thgreasi
Copy link
Owner

Also, what versions of localforage and cordova/ionic do you use?

Thodoris Greasidis
Computer, Networking &
Communications Engineer

@richardelloyd
Copy link
Author

Hello, Cordova is at version 6.1.1 and localforage is at 1.4.2 now.

Currently, I'm using localforage in a separate module and npm installing it within a test app. In the test app, I'm requiring this library at the top of my angular service.

require("localforage-cordovasqlitedriver");

I don't really have a boilerplate that I can share that this came from. It's part of a bigger company project, but its a basic angular, webpack and gulp project. I can provide more details because I know this is pretty vague without a test project. Sorry.

@thgreasi
Copy link
Owner

Does your setup look like this?
https://github.com/cmackay/ionic-webpack

How Cordova SQLite storage plugin
https://github.com/litehelpers/Cordova-sqlite-storage/ is included?
Are you requiring it at all?
You should treat it like a polyfill and load it on its own after the
cordova related files/plugins.
This library expects cordova and cordova sqlite plugin to be already
available when loaded.
We are not require() it explicitely so that the developer can choose to use
a different implementation.

Can you provide any info about the execution of the code of this lib?

Thodoris Greasidis
Computer, Networking &
Communications Engineer

@richardelloyd
Copy link
Author

Issue was fixed. It comes from the way webpack is loading the script. It seems localforage-cordovasqlitedriver is not setup fully for CommonJs(?), so I had to update my webpack config to include a script-loader.

{
    test: require.resolve('localforage-cordovasqlitedriver'),
    loaders: [
        'imports?this=>window',
        'script'
    ]
}

Thanks for your help

@thgreasi
Copy link
Owner

Thanks for sharing your findings, this might prove very useful to others.
Can you help me identify the part that wasn't working for you? I would
suspect globalObject.sqlitePlugin or globalObject.cordova . Was any of them
undefined in your initial implementation?

On Mon, May 23, 2016, 17:37 Rich [email protected] wrote:

Issue was fixed. It comes from the way webpack is loading the script. It
seems localforage-cordovasqlitedriver is not setup fully for CommonJs(?),
so I had to update my webpack config to include a script-loader.

{
test: require.resolve('localforage-cordovasqlitedriver'),
loaders: [
'imports?this=>window',
'script'
]
}

Thanks for your help


You are receiving this because you commented.

Reply to this email directly or view it on GitHub
#10 (comment)

Thodoris Greasidis
Computer, Networking &
Communications Engineer

@richardelloyd
Copy link
Author

Actually, sqlitePlugin and cordova were both defined at startup. My problem was that cordovaSQLiteDriver was not.

@thgreasi
Copy link
Owner

Actually, sqlitePlugin and cordova were both defined at startup.

So these were not undefined, am I right?
Any further details on the way that they were imported?

My problem was that cordovaSQLiteDriver was not.

Can you point a specific line in the src that caused an error or at least the error message that you received?

PS: thanks for your collaboration so far. I just started a branch using rollup that will hopefully make this lib more webpack friendly. I will keep you posted on that.

@richardelloyd
Copy link
Author

Both sqlitePlugin and cordova were defined. I didn't get an error message at all though. It was like the library didn't get loaded, period, but it was still referenced in the resources as loaded. window.cordovaSQLiteDriver was not there within the conditional.

I can look in to it further to get more details on where it dropped off

@thgreasi
Copy link
Owner

Hey there!
Just pushed a new branch that uses es6 modules and rollup and opened PR #11 for merging.
Can you test that it works with your webpack setup? If that's the case, then we could merge it ASAP.
Also, I would be more than happy to review and merge a PR describing how you got it to work with webpack (in case you got some extra time for this and want the credits in your github contributions 😄 ).
Thanks for your collaboration on this issue.

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

No branches or pull requests

2 participants