G
G
GunAlv2020-12-23 17:10:19
JavaScript
GunAlv, 2020-12-23 17:10:19

How to change __dirname in webpack?

By default, __dirname refers to the same directory as the webpack config. If base.config.js is moved to the root, then the dist folder will be compiled there as well. But I need to leave the build logic in the config folder, can you tell me how to do this?
5fe34fe40d734911821998.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Russo2, 2020-12-23
@GunAlv

const path = require('path');

const ROOT_DIR = path.resolve(__dirname, '..');

The ROOT_DIR variable will store the path to the directory above relative to __dirname, now you can specify in the config:
module.exports = {
  output: {
    path: path.resolve(ROOT_DIR, 'dist')
  }
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question