timstuyckens/chromeextensions-knockoutjs

ko not found in webpack project

Closed this issue · 3 comments

I'm bundling knockout with webpack. Like issue #6 I get the error: knockout.js is not used in the page (ko is undefined). Maybe you are using iFrames, if so, browse to the url of the frame and try again.
I've tried (this is typescript) in my entry point:

(<any>window).ko = ko;

Would the webpack ProvidePlugin help with this?

You can use expose loader to make knockout global variable again.
Example configuration:

rules: [
  {
    test: require.resolve('knockout'),
    use: [
      {
        loader: 'expose-loader',
        options: 'ko',
      },
    ],
  },
],

You can also use this configuration only for development mode.

Thanks. I've moved to Angular so this is no longer an issue for me.