T
T
thehighhomie2020-01-28 15:06:24
webpack
thehighhomie, 2020-01-28 15:06:24

Weback + Babel: Modules not being exported?

Why can't I export anything from the index.js file, which is collected in dist, in webpack via babel, that is, I take for example in src/index.js I write export const { name: 'Mike }that when compiling into a bundle and connecting this file, I get an empty object?

I understand this is a problem with babel

here is my webpack config:

const path = require('path')

const webpackConfig = {
  entry: {
    index: path.resolve(__dirname, '../src', 'index.js'),
    main: path.resolve(__dirname, '../src', 'main.js'),
    test: path.resolve(__dirname, '../src', 'test.js')
  },

  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, '../dist')
  },

  module: {
    rules: [
      { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' }
    ]
  }
}


module.exports = webpackConfig

and here is babel.config.js
module.exports = {
  presets: [
    '@babel/preset-env'
  ],

  plugins: [
    '@babel/plugin-transform-runtime',
    '@babel/plugin-transform-async-to-generator'
  ]
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question