Skip to content

Commit afc54dc

Browse files
fix: output multiple targets (#118)
* fix: output multiple targets * use more common file names Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
1 parent 6fc19a8 commit afc54dc

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
"files": [
1212
"/dist"
1313
],
14-
"main": "dist/",
15-
"module": "dist/index.js",
14+
"exports": {
15+
".": {
16+
"require": "./dist/index.cjs",
17+
"default": "./dist/index.mjs"
18+
}
19+
},
1620
"keywords": [
1721
""
1822
],
@@ -61,7 +65,8 @@
6165
"build": "NODE_ENV=production webpack",
6266
"lint": "eslint lib --max-warnings 0 && prettier lib --check",
6367
"test": "jest",
64-
"prepublishOnly": "npm run build"
68+
"prepublishOnly": "npm run build",
69+
"webpack": "webpack"
6570
},
6671
"repository": "git@github.com:freeCodeCamp/curriculum-helpers.git",
6772
"jest": {

webpack.config.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
const path = require("path");
22

33
console.info("Building in " + process.env.NODE_ENV + " mode.");
4-
module.exports = {
5-
mode: process.env.NODE_ENV ? "production" : "development",
4+
const baseConfig = {
5+
mode: process.env.NODE_ENV,
66
entry: {
77
index: "./lib/index.ts",
88
},
9-
devtool: process.env.NODE_ENV ? "source-map" : "inline-source-map",
10-
output: {
11-
globalObject: 'this',
12-
library: {
13-
name: "helpers",
14-
type: "umd",
15-
},
16-
},
9+
devtool:
10+
process.env.NODE_ENV === "production" ? "source-map" : "inline-source-map",
1711
module: {
1812
rules: [
1913
{
@@ -30,3 +24,33 @@ module.exports = {
3024
},
3125
},
3226
};
27+
28+
const nodeConfig = {
29+
...baseConfig,
30+
target: "node",
31+
output: {
32+
library: {
33+
type: "commonjs",
34+
},
35+
filename: "index.cjs",
36+
path: path.resolve(__dirname, "dist"),
37+
},
38+
};
39+
40+
const browserConfig = {
41+
...baseConfig,
42+
target: "web",
43+
experiments: {
44+
outputModule: true,
45+
},
46+
output: {
47+
library: {
48+
type: "module",
49+
// type: "commonjs-static",
50+
},
51+
filename: "index.mjs",
52+
path: path.resolve(__dirname, "dist"),
53+
},
54+
};
55+
56+
module.exports = [nodeConfig, browserConfig];

0 commit comments

Comments
 (0)