Skip to content

Commit

Permalink
Merge pull request #368 from gligorkot/fix-node-modules-relative-dir
Browse files Browse the repository at this point in the history
Expose nodeModulesRelativeDir serverless-webpack config
  • Loading branch information
jayair authored Nov 30, 2023
2 parents e1ae01a + cfb2c53 commit bf18ef3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ tsconfig.tsbuildinfo
.serverless
.webpack
.cache-loader
.idea/*
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ custom:
packagerOptions: # Run a custom script in the package process
scripts: # https://github.com/serverless-heaven/serverless-webpack#custom-scripts
- echo hello > test
nodeModulesRelativeDir: '../' # Useful for monorepos if you have your node_modules in the root directory
# https://github.com/serverless-heaven/serverless-webpack#node-modules--externals
rawFileExtensions: # An array of file extensions to import using the Webpack raw-loader.
- csv # Defaults to ['pem', 'txt']
minifyOptions: # Options for ESBuildMinifyPlugin (https://esbuild.github.io/api/#simple-options)
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ function applyWebpackOptions(custom, config) {
includeModules: {
forceExclude: config.options.forceExclude,
forceInclude: config.options.forceInclude,
nodeModulesRelativeDir:
config.options.nodeModulesRelativeDir != null
? config.options.nodeModulesRelativeDir
: "./",
// Generate relative path for the package.json
// For cases where the services are nested and don't have their own package.json
// Traverse up the tree to find the path to the nearest package.json
//
// Certain plugins like serverless-plugin-typescript change the cwd, so when
// searching, reset the the cwd to the service path
// searching, reset the cwd to the service path
packagePath: path.relative(
config.servicePath,
pkgUp.sync({ cwd: config.servicePath })
Expand Down Expand Up @@ -57,7 +61,7 @@ function applyUserConfig(config, userConfig, servicePath, runtime) {
);
}

// Concat externals if provided
// Concat rawFileExtensions if provided
if (userConfig.rawFileExtensions) {
userConfig.rawFileExtensions = config.options.rawFileExtensions.concat(
userConfig.rawFileExtensions
Expand Down

0 comments on commit bf18ef3

Please sign in to comment.