localForage: localForage 1.2.2 + webpack 1.5.3 doesn't want to collaborate

Hello. It seems that this PR don’t fix problem of using localForage with webpack. I’ve created gist to illustrate problem https://gist.github.com/ALF-er/83325c24019de4edc851 (just place file index.html in ./src/ dir and main.js in ./src/js/ dir). If I run “npm run dev” (it just copy index.html in ./dist/ dir, compile main.js with webpack and then run webpack-dev-server for ./dist/) I get:

WARNING in ./~/localforage/src/localforage.js
Critical dependencies:
332:20-336:22 the request of a dependency is an expression
 @ ./~/localforage/src/localforage.js 332:20-336:22

ERROR in ./~/localforage/src/drivers/localstorage.js
Module not found: Error: Cannot resolve module 'localforageSerializer' in C:\dev\projects\wp_lf_test\node_modules\localforage\src\drivers
 @ ./~/localforage/src/drivers/localstorage.js 70:16-59

ERROR in ./~/localforage/src/drivers/websql.js
Module not found: Error: Cannot resolve module 'localforageSerializer' in C:\dev\projects\wp_lf_test\node_modules\localforage\src\drivers
 @ ./~/localforage/src/drivers/websql.js 63:16-59

If in main.js uncomment second line (and comment first ofc) then it builds w/o errors but in browser console I get localForage.getItem - undefined function…

Maybe you can suggest something?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 30 (14 by maintainers)

Most upvoted comments

@prakhar1989 you need to install exports-loader: npm i -S exports-loader

You’re right, I missed this part of the config:

        noParse: [
            /localforage\/dist\/localforage.js/
        ]

so the whole thing is:

module.exports = {
    module: {
        loaders: [{
            test: /localforage\/dist\/localforage.js/,
            loader: 'exports?localforage',
        }],
        noParse: [
            /localforage\/dist\/localforage.js/
        ]
    },
    resolve: {
        alias: {
            'localforage': 'localforage/dist/localforage.js'
        }
    }
};