Skip to content

Commit

Permalink
Build: Replace parcel bundler with webpack
Browse files Browse the repository at this point in the history
As parcel lead to issues with webpack, we now also use webpack as bundler.

For more information look at parcel-bundler/parcel#2883
  • Loading branch information
markusguenther committed Mar 6, 2021
1 parent 3db500c commit 1d461d4
Show file tree
Hide file tree
Showing 32 changed files with 1,096 additions and 2,976 deletions.
10 changes: 10 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
]
]
}
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
.cache
/node_modules
.cache/
coverage/
node_modules/
*.log

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Binary file removed .parcel-cache/05/3937b4d3c54893645cff7ea520bb8d.blob
Binary file not shown.
Binary file removed .parcel-cache/0a/f77a354a2070e8e281b2da7d1d0fd6.v8
Binary file not shown.
2 changes: 0 additions & 2 deletions .parcel-cache/0f/2bc56b364c9455e341b9205ad9961d.txt

This file was deleted.

Binary file removed .parcel-cache/10/902da83893992f11b6bf27d80739ca.v8
Binary file not shown.
2 changes: 0 additions & 2 deletions .parcel-cache/28/54a7514328a681723b2b5438586708.blob

This file was deleted.

Binary file not shown.
Binary file removed .parcel-cache/30/ef1edcd6452fc8f22db0ebf9d92bc1.v8
Binary file not shown.
Binary file removed .parcel-cache/3c/70df389337a5f55bef0109a6294f16.v8
Binary file not shown.
Binary file removed .parcel-cache/41/7d0ecc632a78e3d6fbc5b520f7de83.v8
Binary file not shown.
1 change: 0 additions & 1 deletion .parcel-cache/5d/307ffd3e835a8d836af5f5c8e86a18.blob

This file was deleted.

2 changes: 0 additions & 2 deletions .parcel-cache/63/f0cb0d270378216f34bcea61796730.blob

This file was deleted.

Binary file removed .parcel-cache/84/aea496325fcc5a38254e933e1be191.blob
Binary file not shown.
1 change: 0 additions & 1 deletion .parcel-cache/87/c964afcb020f67a79fd495ab6a72ce.blob

This file was deleted.

Binary file removed .parcel-cache/94/b9ff5ed0c5b32cd772db111adb05ac.v8
Binary file not shown.
Binary file removed .parcel-cache/9c/7e2046adeb9d1c2c3d9177b56bc4d1.v8
Binary file not shown.
Binary file removed .parcel-cache/aa/d2ce5ba75d6a4c3067e28b5008abce.v8
Binary file not shown.
Binary file removed .parcel-cache/ac/303eb4ead806f883b53f488721d4aa.blob
Binary file not shown.
Binary file removed .parcel-cache/ae/b9969937b3f8f7551fafbad32360bb.blob
Binary file not shown.
Binary file removed .parcel-cache/b0/31fa22f53fce4b16f8448bc4bc2110.blob
Binary file not shown.
Binary file removed .parcel-cache/b8/933e01f171819d94dafe1e0f8a1e5f.blob
Binary file not shown.
Binary file removed .parcel-cache/c3/31149155c454ec15ee827f6d8a7a56.v8
Binary file not shown.
Binary file removed .parcel-cache/e5/521ca33d53d966033fb09e34d36acc.v8
Binary file not shown.
Binary file removed .parcel-cache/ef/739abe051d2eb05ead189c3874eece.v8
Binary file not shown.
9 changes: 1 addition & 8 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dist/index.js.map

This file was deleted.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.1",
"repository": "https://github.com/Unikka/loginas-api.git",
"license": "MIT",
"main": "dist/index.js",
"main": "index.js",
"dependencies": {
"core-js": "^3.8.0",
"regenerator-runtime": "^0.13.7"
Expand All @@ -12,8 +12,9 @@
"test": "echo \"Error: no test specified\" && exit 0",
"semantic-release": "semantic-release",
"commit": "git-cz",
"build": "parcel build src/index.js --out-dir dist/",
"watch": "parcel watch src/index.js --out-dir dist/"
"clean": "rm dist/index.js",
"build-dev": "webpack --mode development",
"build-prod": "webpack --mode production"
},
"devDependencies": {
"@semantic-release/changelog": "^5.0.1",
Expand All @@ -22,7 +23,11 @@
"commitizen": "^4.1.2",
"conventional-changelog-eslint": "^3.0.8",
"cz-adapter-eslint": "^0.3.0",
"parcel": "1.12.3",
"webpack": "^5.22.0",
"webpack-cli": "^4.5.0",
"babel-loader": "^8.2.2",
"@babel/core": "^7.12.16",
"@babel/preset-env": "^7.12.16",
"prettier": "^2.2.1",
"semantic-release": "^17.0.8"
},
Expand Down
63 changes: 63 additions & 0 deletions src/Service/ApiService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { isNil } from '../Helper'

export default class ApiService {
constructor(_basePath, _csrfToken) {
if (isNil(_basePath)) {
const pathError = 'Tried to create API service without a base uri. '
pathError += 'Please initialize the API service with a base path '
pathError += 'like "/neos/impersonate/"'
console.error(pathError)
}
this._basePath = _basePath

if (isNil(_csrfToken)) {
const csrfError = 'Tried to create API service without a CSFR '
csrfError += 'token. Please initialize the API service with a token'
console.error(csrfError)
}
this._csrfToken = _csrfToken
}

async callUserChange(identifier) {
const data = {
user: identifier,
format: 'json',
}
const response = await fetch(this._basePath + 'user-change', {
method: 'POST',
credentials: 'include',
headers: this._getHeader(),
body: JSON.stringify(data),
})

return await response.json()
}

async callStatus() {
const response = await fetch(this._basePath + 'status', {
method: 'GET',
credentials: 'include',
headers: this._getHeader(),
})

return await response.json()
}

async callRestore() {
const response = await fetch(this._basePath + 'restore', {
method: 'POST',
credentials: 'include',
headers: this._getHeader(),
})

return await response.json()
}

_getHeader() {
return {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-Flow-Csrftoken': this._csrfToken,
}
}
}
64 changes: 2 additions & 62 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,3 @@
import { isNil } from './Helper'
import ApiService from './Service/ApiService'

export default class ApiService {
constructor(_basePath, _csrfToken) {
if (isNil(_basePath)) {
const pathError = 'Tried to create API service without a base uri. '
pathError += 'Please initialize the API service with a base path '
pathError += 'like "/neos/impersonate/"'
console.error(pathError)
}
this._basePath = _basePath

if (isNil(_csrfToken)) {
const csrfError = 'Tried to create API service without a CSFR '
csrfError += 'token. Please initialize the API service with a token'
console.error(csrfError)
}
this._csrfToken = _csrfToken
}

async callUserChange(identifier) {
const data = {
user: identifier,
format: 'json',
}
const response = await fetch(this._basePath + 'user-change', {
method: 'POST',
credentials: 'include',
headers: this._getHeader(),
body: JSON.stringify(data),
})

return await response.json()
}

async callStatus() {
const response = await fetch(this._basePath + 'status', {
method: 'GET',
credentials: 'include',
headers: this._getHeader(),
})

return await response.json()
}

async callRestore() {
const response = await fetch(this._basePath + 'restore', {
method: 'POST',
credentials: 'include',
headers: this._getHeader(),
})

return await response.json()
}

_getHeader() {
return {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-Flow-Csrftoken': this._csrfToken,
}
}
}
export default ApiService
25 changes: 25 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const webpack = require('webpack')
const path = require('path')

const config = {
entry: './src/index.js',
output: {
path: path.resolve('dist'),
filename: 'index.js',
libraryTarget: 'commonjs2',
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.js'],
},
}

module.exports = config
Loading

0 comments on commit 1d461d4

Please sign in to comment.