最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Creating files in a sibling directory - Stack Overflow

programmeradmin7浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论