Closed its-dibo closed 3 years ago
@eng-dibo note that you need to specify it like so:
config.externals.push(
nodeExternals({
modulesFromFile: {
fileName: path.join(__dirname, "./package.json")
}
})
);
Closing this as it should be resolved with the correct config structure, please let me know if it doesn't work
this package assumes that the file
package.json
is located insideprocess.cwd()
which is not a must. the location of this file must be relative to the current file (i.e: webpack.config.js) by default which is more expected.https://github.com/liady/webpack-node-externals/blob/6dc8265e24788b70add4e2bf50fd1a13581d18af/utils.js#L53
use case:
if you use a single package.json file to control multiple projects (monorepo), and each file has it's own package.json file contains it's own scripts, but not dependencies.
if you want to run
build
for any project from the workspace's root, rather than the project's root usingnpm --prefix
flagin this case
process.cwd()
refers to projects/example which doesn't contain the dependencies field in it's package.json file, but it is located in the workspace's root (i.e: ../../package.json). it is more easily to refer to the correct package.json path relative to the current webpack configuration file, so it is fixed regardless of the current working directory.even using
options.filename
doesn't help:__dirname here refers to the directory where webpack.config.js is located.