Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose nodeModulesRelativeDir serverless-webpack config #368

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading