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 Webpack resolve alias and modules properties #460

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ require('@zeit/ncc')('/path/to/input', {
watch: false, // default
v8cache: false, // default
quiet: false, // default
debugLog = false // default
debugLog = false, // default
// https://webpack.js.org/configuration/resolve/#resolvealias
resolveAlias: {}, // default
// https://webpack.js.org/configuration/resolve/#resolvemodules
resolveModules: [] // default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to avoid leaking webpack details through to the ncc API in case we need to swap webpack for rollup or some other alternative.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other tools likely have similar options; Rollup for sure does.

Changing build tool would definitely be a breaking change, if it ever happens, so I don't particularly see the issue with supporting a particular flavor of options.

This option would reduce my bundle by dropping 2 unused heavy sub-dependencies. I just realized that my built file is 1.2MB due a couple of dependencies I don't really use.

}).then(({ code, map, assets }) => {
console.log(code);
// Assets is an object of asset file names to { source, permissions, symlinks }
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ module.exports = (
v8cache = false,
filterAssetBase = process.cwd(),
quiet = false,
debugLog = false
debugLog = false,
resolveAlias = {},
resolveModules = []
} = {}
) => {
if (!quiet) {
Expand Down Expand Up @@ -128,10 +130,12 @@ module.exports = (
libraryTarget: "commonjs2"
},
resolve: {
alias: resolveAlias,
extensions: SUPPORTED_EXTENSIONS,
// webpack defaults to `module` and `main`, but that's
// not really what node.js supports, so we reset it
mainFields: ["main"],
modules: ['node_modules'].concat(resolveModules),
plugins: resolvePlugins
},
// https://github.com/zeit/ncc/pull/29#pullrequestreview-177152175
Expand Down