Issue exporting functions using Webpack 5

Viewed 64

Given an exported funtion createTableFromJSON(json) from the entry file index.js and this config example that follows the specifications given on the official Webpack wiki:

const config = {
  entry: './assets/javascripts/index.js',
  output: {
    library: {
      name: 'HotchPotch',
      type: 'global'
    },
    libraryTarget: 'var',
    path: path.resolve(__dirname, 'static'), // Should be in STATICFILES_DIRS
    publicPath: '/static/', // Should match Django's STATIC_URL
    // filename: '[name].js', // No filename hashing, Django takes care of this
    filename: 'main.js',
    // chunkFilename: '[id]-[chunkhash].js', // DO have Webpack hash chunk filename
    clean: true
  },

Function exports would be expected to appear, but are not. HotchPotch also is logged as being undefined. What's the issue with this configuration?

1 Answers

I figured out that accessing an exported method through the variable global is needed.

Related