I'm in a situation where I want to create "dist" files along a dynamic path but in a specific child directory, which is a sibling to the source directory.
My project structure ideally looks like this:
- files/
- directory1/
- src/
- index.js
- dist/
- index-dist.js
- directory2/
- src/
- index.js
- dist/
- index-dist.js
What I have so far in my Webpack config:
const path = require( 'path' );
const glob = require('glob');
module.exports = ( env ) => {
return {
entry: Object.fromEntries(glob.sync(path.resolve(__dirname, 'files/**/src/index.js')).map((v) => [ v.split('files/')[1], v, ] )),
resolve: {
extensions: [
'.js',
],
},
output: {
path: path.resolve( __dirname, 'files' ),
filename: '[name]-dist.js',
},
}
};
However, this is producing:
- files/
- directory1/
- src/
- index.js <- this is my entry point
- index.js-dist.js <- this is the output
- directory2/
- src/
- index.js <- this is my entry point
- index.js-dist.js <- this is the output
I saw there was something with [path]
that could theoretically be used, but it just created a folder called "[path]" when I tried that.