I have been struggling for the past couple days to get this working properly.
I have two classes in two different js files:
file src/a.js:
export default class A {}
file src/b.js:
export default class B {}
and I have the following entrypoint file:
file src/index.js:
import A from './a.js'
import B from './b.js'
export { A, B }
// I don't know what else should go in here
I build it using this webpack config:
file webpack.config.js:
module.exports = {
input: 'src/index.js',
output: {
path: 'dist/',
filename: 'my-lib.js',
libraryTarget: 'commonjs-module',
}
}
And build it with the webpack command.
Another thing to note is the package.json:
file package.json:
{
"name": "my-library",
"module": "dist/my-lib.js",
"main": "dist/my-lib.js"
}
The goal is to import my node module in another project atfer installing it:
$ npm install --save my-module
And use it like this:
import {A,B} from 'my-module'
const a = new A()
const b = new B()
How do I create such an index.js file and how should my webpack.config.js file look to be able to do this?