Skip to content

Commit 3eb6b2d

Browse files
committed
Add browser-friendly CommonJS export.
1 parent 816cc78 commit 3eb6b2d

8 files changed

Lines changed: 147 additions & 16 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
browser
12
coverage
23
dist-lib
34
dist-popup

package-lock.json

Lines changed: 80 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
"version": "2.2.10",
44
"description": "Opaquely authenticates solid clients",
55
"main": "lib/index-default.js",
6+
"browser": "browser/index.js",
67
"module": "module/index.js",
78
"engines": {
89
"node": ">=8.0.0"
910
},
1011
"bin": "./bin/solid-auth-client.js",
1112
"files": [
1213
"bin",
13-
"dist-lib",
14-
"dist-popup",
1514
"lib",
16-
"module"
15+
"module",
16+
"browser",
17+
"dist-lib",
18+
"dist-popup"
1719
],
1820
"repository": "git@github.com:solid/solid-auth-client.git",
1921
"author": "Daniel Friedman <dfriedman58@gmail.com>",
@@ -38,10 +40,11 @@
3840
"test:dev": "npm run jest -- --watch",
3941
"test:debug": "node --debug-brk ./node_modules/.bin/jest --runInBand src",
4042
"coverage:report": "cat ./coverage/lcov.info | coveralls",
41-
"build": "npm run build:lib && npm run build:module && npm run build:lib:umd && npm run build:popup:template",
43+
"build": "npm run build:lib && npm run build:module && npm run build:window && npm run build:browser && npm run build:popup:template",
4244
"build:lib": "rm -rf lib && babel src --env-name production -d lib",
4345
"build:module": "rm -rf module && babel src --env-name module -d module",
44-
"build:lib:umd": "webpack --config=./webpack/webpack.lib.config.js -p",
46+
"build:window": "webpack --config=./webpack/webpack.window.config.js -p",
47+
"build:browser": "webpack --config=./webpack/webpack.browser.config.js",
4548
"build:demo": "webpack --config=./webpack/webpack.demo.config.js -p",
4649
"build:popup": "webpack --config=./webpack/webpack.popup.config.js -p && rm ./dist-popup/popup.bundle.js && bin/solid-auth-client.js generate-popup '' dist-popup/popup.html",
4750
"build:popup:template": "cross-env APP_NAME='{{APP_NAME}}' npm run build:popup",
@@ -94,6 +97,7 @@
9497
"preact-compat": "^3.17.0",
9598
"prettier": "^1.5.3",
9699
"prettier-eslint": "^8.8.1",
100+
"replace-in-file-webpack-plugin": "^1.0.6",
97101
"rsa-pem-to-jwk": "^1.1.3",
98102
"style-loader": "^0.23.0",
99103
"webpack": "^4.20.2",

webpack/webpack.browser.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* Browser-friendly CommonJS bundle that exports solid-auth-client */
2+
3+
const path = require('path')
4+
const CleanWebpackPlugin = require('clean-webpack-plugin')
5+
const ReplaceInFileWebpackPlugin = require('replace-in-file-webpack-plugin');
6+
const {
7+
context,
8+
mode,
9+
entry,
10+
module: _module,
11+
externals,
12+
devtool
13+
} = require('./webpack.common.config')
14+
15+
const outputDir = './browser'
16+
17+
module.exports = {
18+
context,
19+
mode,
20+
entry,
21+
output: {
22+
filename: 'index.js',
23+
path: path.resolve(outputDir),
24+
libraryExport: 'default',
25+
library: 'exports',
26+
libraryTarget: 'window'
27+
},
28+
module: _module,
29+
externals,
30+
plugins: [
31+
// Replace the assignment to window by a module export
32+
new ReplaceInFileWebpackPlugin([{
33+
dir: outputDir,
34+
files: ['index.js'],
35+
rules: [{
36+
search: 'window["exports"]',
37+
replace: 'module.exports'
38+
}]
39+
}]),
40+
new CleanWebpackPlugin([outputDir]),
41+
],
42+
devtool
43+
}

webpack/webpack.common.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
/* Shared webpack configuration */
2+
13
const path = require('path')
24

35
module.exports = {
46
context: path.resolve(__dirname, '..'),
57
mode: 'none',
8+
entry: {
9+
'solid-auth-client': './src/index.js'
10+
},
611
module: {
712
rules: [
813
{

webpack/webpack.demo.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* HTML bundle of the demo application */
2+
13
const CleanWebpackPlugin = require('clean-webpack-plugin')
24
const HtmlWebpackPlugin = require('html-webpack-plugin')
35
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')

webpack/webpack.popup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* HTML bundle of the popup application */
2+
13
const CleanWebpackPlugin = require('clean-webpack-plugin')
24
const HtmlWebpackPlugin = require('html-webpack-plugin')
35
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
/* Browser bundle that exposes solid-auth-client as window.solid.auth */
2+
13
const path = require('path')
24
const CleanWebpackPlugin = require('clean-webpack-plugin')
35
const {
46
context,
57
mode,
8+
entry,
69
module: _module,
710
externals,
811
devtool
@@ -13,18 +16,12 @@ const outputDir = './dist-lib'
1316
module.exports = {
1417
context,
1518
mode,
16-
entry: {
17-
'solid-auth-client': './src/index.js'
18-
},
19+
entry,
1920
output: {
2021
filename: '[name].bundle.js',
2122
path: path.resolve(outputDir),
2223
libraryExport: 'default',
23-
library: {
24-
root: ['solid', 'auth'],
25-
amd: 'solid-auth-client',
26-
commonjs: 'solid-auth-client'
27-
},
24+
library: ['solid', 'auth'],
2825
libraryTarget: 'umd'
2926
},
3027
module: _module,

0 commit comments

Comments
 (0)