Skip to content

Commit

Permalink
Merge pull request #34 from CanopyTax/externals-submodule
Browse files Browse the repository at this point in the history
Add support for externals
  • Loading branch information
rhys-childs authored Oct 29, 2024
2 parents dfc43a2 + e3f185b commit 164722e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @CanopyTax/frontend-leads
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,17 @@ canopy-webpack-config assumes a few things about your project and provides defau
the webpack config for canopy-webpack-config will always create the output bundle in the directory that the webpack process was started in. This
is different than how webpack configs normally work -- they usually create the output bundle in relation to the directory in which the webpack config
file is placed.

## Optional modifiers
We support a few config options for builds, including typescript and an externals submodule.
```
module.exports = canopyWebpackConfig('login-ui', {}, {
typescript: true,
externals: true
})
```
### Typescript `<bool>`
Pass an options object with `{typescript: true}` when your service uss typescript.

### Externals `<bool>`
Pass an options object with `{externals: true}` when you are looking to export a submodule from `/src/externals.{js|ts}`. This should be for exports that must be imported synchronously such as hooks or queries that do not have other internal dependencies (to avoid circular dependencies).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canopy-webpack-config",
"version": "4.1.1",
"version": "4.2.0",
"description": "Some defaults for webpack configs at canopy",
"main": "src/canopy-webpack-config.js",
"repository": "git@github.com:CanopyTax/canopy-webpack-config.git",
Expand Down
12 changes: 9 additions & 3 deletions src/canopy-webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const port =
? process.argv[portIndex + 1]
: "8080";

module.exports = function (name, overridesConfig = {}, typescript) {
module.exports = function (name, overridesConfig = {}, options = {}) {
const { typescript, externals } = options;
if (typeof name !== "string") {
throw new Error(
"canopy-webpack-config expects a string name as the first argument"
Expand All @@ -47,9 +48,14 @@ module.exports = function (name, overridesConfig = {}, typescript) {
}

const defaultCanopyConfig = {
entry: `./src/${name}.${typescript ? "ts" : "js"}`,
entry: {
[name]: `./src/${name}.${typescript ? "ts" : "js"}`,
...(externals && {
externals: `./src/externals.${typescript ? "ts" : "js"}`,
}),
},
output: {
filename: `${name}.js`,
filename: (pathData) => `${pathData.chunk.name}.js`,
publicPath: "",
uniqueName: name,
library: {
Expand Down

0 comments on commit 164722e

Please sign in to comment.