Pack frontend into binary

Improved webpack

Signed-off-by: Jonas Franz <info@jonasfranz.software>
web-ui
Jonas Franz 6 years ago committed by Jonas Franz
parent a7a8b42c59
commit 79e87b0bb9
Signed by untrusted user: JonasFranzDEV
GPG Key ID: 506AEEBE80BEDECD
  1. 11
      .drone.yml
  2. 1
      .gitignore
  3. 14
      Gopkg.lock
  4. 4
      Gopkg.toml
  5. 18
      api/fs.go
  6. 5
      api/router.go
  7. 18
      frontend/index.html
  8. 2
      frontend/package.json
  9. 7
      frontend/src/index.html
  10. 125
      frontend/webpack.config.js
  11. 78
      frontend/yarn.lock

@ -28,7 +28,7 @@ pipeline:
commands: commands:
- cd frontend/ - cd frontend/
- yarn build - yarn build
deps: build:
image: golang:1.10 image: golang:1.10
pull: true pull: true
environment: environment:
@ -36,6 +36,8 @@ pipeline:
commands: commands:
- go get -u github.com/golang/dep/cmd/dep - go get -u github.com/golang/dep/cmd/dep
- dep ensure - dep ensure
- go get -u github.com/gobuffalo/packr/...
- packr -z
test: test:
image: golang:1.10 image: golang:1.10
pull: true pull: true
@ -56,6 +58,13 @@ pipeline:
- xgo -out gitea-github-migrator -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" --targets=windows/*,darwin/*,linux/* . - xgo -out gitea-github-migrator -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" --targets=windows/*,darwin/*,linux/* .
when: when:
event: [ tag ] event: [ tag ]
clean:
image: golang:1.10
pull: true
environment:
GOPATH: /go
commands:
- packr clean
gitea: gitea:
image: plugins/gitea-release:latest image: plugins/gitea-release:latest
pull: true pull: true

1
.gitignore vendored

@ -10,6 +10,7 @@
# Output of the go coverage tool, specifically when used with LiteIDE # Output of the go coverage tool, specifically when used with LiteIDE
*.out *.out
*-packr.go
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/ .glide/

14
Gopkg.lock generated

@ -35,6 +35,12 @@
revision = "d459835d2b077e44f7c9b453505ee29881d5d12d" revision = "d459835d2b077e44f7c9b453505ee29881d5d12d"
version = "v1.2" version = "v1.2"
[[projects]]
name = "github.com/gobuffalo/packr"
packages = ["."]
revision = "bd47f2894846e32edcf9aa37290fef76c327883f"
version = "v1.11.1"
[[projects]] [[projects]]
name = "github.com/golang/protobuf" name = "github.com/golang/protobuf"
packages = ["proto"] packages = ["proto"]
@ -65,6 +71,12 @@
revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
version = "v0.0.3" version = "v0.0.3"
[[projects]]
name = "github.com/pkg/errors"
packages = ["."]
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
version = "v0.8.0"
[[projects]] [[projects]]
name = "github.com/ugorji/go" name = "github.com/ugorji/go"
packages = ["codec"] packages = ["codec"]
@ -131,6 +143,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "2884c43b72546db916785490241c84920a25e0f43df532f9b3a551a678e3cc42" inputs-digest = "4a75dbc846a83d2e7c1a0d840da062e06835663a2a4a60225d41ee22a89db840"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

@ -51,3 +51,7 @@
[[constraint]] [[constraint]]
branch = "master" branch = "master"
name = "github.com/jinzhu/configor" name = "github.com/jinzhu/configor"
[[constraint]]
name = "github.com/gobuffalo/packr"
version = "1.11.1"

@ -0,0 +1,18 @@
package api
import (
"strings"
"github.com/gobuffalo/packr"
)
type BundledFS struct {
packr.Box
}
func (fs *BundledFS) Exists(prefix string, filepath string) bool {
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) {
return fs.Has(p)
}
return false
}

@ -22,12 +22,15 @@ import (
"git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator/api/auth" "git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator/api/auth"
"github.com/gin-gonic/contrib/static" "github.com/gin-gonic/contrib/static"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gobuffalo/packr"
) )
func InitRoutes() *gin.Engine { func InitRoutes() *gin.Engine {
r := gin.Default() r := gin.Default()
auth.InitOAuthConfig() auth.InitOAuthConfig()
r.Use(static.Serve("/", static.LocalFile("./frontend", true)))
box := packr.NewBox("../frontend/dist/")
r.Use(static.Serve("/", &BundledFS{box}))
api := r.Group("/api") api := r.Group("/api")
{ {
au := api.Group("/auth") au := api.Group("/auth")

@ -1,18 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Gitea Migrator</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.1/semantic.min.css"/>
</head>
<body>
<div id="example"></div>
<!-- Dependencies -->
<script src="./node_modules/react/umd/react.development.js"></script>
<script src="./node_modules/react-dom/umd/react-dom.development.js"></script>
<script src="./node_modules/semantic-ui-react/dist/umd/semantic-ui-react.min.js"></script>
<!-- Bundles -->
<script type="text/javascript" src="dist/bundle.js"></script></body>
</html>

@ -23,7 +23,9 @@
"babel-loader": "^7.1.4", "babel-loader": "^7.1.4",
"babel-preset-env": "^1.7.0", "babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1", "babel-preset-react": "^6.24.1",
"copy-webpack-plugin": "^4.5.1",
"html-loader": "^0.5.5", "html-loader": "^0.5.5",
"html-webpack-externals-plugin": "^3.8.0",
"html-webpack-plugin": "^3.2.0", "html-webpack-plugin": "^3.2.0",
"husky": "^0.14.3", "husky": "^0.14.3",
"prettier": "1.13.5", "prettier": "1.13.5",

@ -7,12 +7,5 @@
</head> </head>
<body> <body>
<div id="example"></div> <div id="example"></div>
<!-- Dependencies -->
<script src="./node_modules/react/umd/react.development.js"></script>
<script src="./node_modules/react-dom/umd/react-dom.development.js"></script>
<script src="./node_modules/semantic-ui-react/dist/umd/semantic-ui-react.min.js"></script>
<!-- Bundles -->
</body> </body>
</html> </html>

@ -1,65 +1,76 @@
var HtmlWebPackPlugin = require("html-webpack-plugin"); var HtmlWebPackPlugin = require("html-webpack-plugin");
var CopyWebpackPlugin = require("copy-webpack-plugin");
var HtmlWebpackExternalsPlugin = require("html-webpack-externals-plugin");
module.exports = { module.exports = {
entry: "./src/index.tsx", entry: "./src/index.tsx",
output: { output: {
filename: "bundle.js", filename: "bundle.js",
path: __dirname + "/dist" path: __dirname + "/dist"
}, },
// Enable sourcemaps for debugging webpack's output. // Enable sourcemaps for debugging webpack's output.
devtool: "source-map", devtool: "source-map",
mode: "development", mode: "development",
resolve: { resolve: {
// Add '.ts' and '.tsx' as resolvable extensions. // Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"] extensions: [".ts", ".tsx", ".js", ".json"]
}, },
module: {
module: { rules: [
rules: [ // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'. {
{ test: /\.tsx?$/, use: [ test: /\.tsx?$/,
{ use: [
loader: 'babel-loader', {
options: { loader: "babel-loader",
babelrc: false, options: {
plugins: ['react-hot-loader/babel'] babelrc: false,
} plugins: ["react-hot-loader/babel"]
}, }
'awesome-typescript-loader' },
] "awesome-typescript-loader"
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader'
}
]
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
] ]
}, },
plugins: [ {
new HtmlWebPackPlugin( test: /\.html$/,
{ use: [
template: "./src/index.html", {
filename: "./index.html" loader: "html-loader"
} }
) ]
], },
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
// When importing a module whose path matches one of the following, just plugins: [
// assume a corresponding global variable exists and use that instead. new HtmlWebPackPlugin({
// This is important because it allows us to avoid bundling all of our template: "./src/index.html",
// dependencies, which allows browsers to cache those libraries between builds. filename: "./index.html"
externals: { }),
"react": "React", new HtmlWebpackExternalsPlugin({
"react-dom": "ReactDOM", externals: [
"semantic-ui-react": "semanticUIReact" {
} module: "react",
}; entry: "umd/react.development.js",
global: "React"
},
{
module: "react-dom",
entry: "umd/react-dom.development.js",
global: "ReactDOM"
},
{
module: "semantic-ui-react",
entry: "dist/umd/semantic-ui-react.min.js",
global: "semanticUIReact"
}
]
}),
new CopyWebpackPlugin([{ from: "assets", to: "assets" }])
]
};

@ -214,6 +214,15 @@ ajv@^6.1.0:
json-schema-traverse "^0.3.0" json-schema-traverse "^0.3.0"
uri-js "^4.2.1" uri-js "^4.2.1"
ajv@^6.1.1:
version "6.5.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.5.1.tgz#88ebc1263c7133937d108b80c5572e64e1d9322d"
dependencies:
fast-deep-equal "^2.0.1"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.4.1"
uri-js "^4.2.1"
ansi-escapes@^3.0.0: ansi-escapes@^3.0.0:
version "3.1.0" version "3.1.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.1.0.tgz#f73207bb81207d75fd6c83f125af26eea378ca30" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.1.0.tgz#f73207bb81207d75fd6c83f125af26eea378ca30"
@ -309,6 +318,10 @@ array-unique@^0.3.2:
version "0.3.2" version "0.3.2"
resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428" resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428"
arrify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
asap@~2.0.3: asap@~2.0.3:
version "2.0.6" version "2.0.6"
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46" resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
@ -1361,6 +1374,19 @@ copy-descriptor@^0.1.0:
version "0.1.1" version "0.1.1"
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
copy-webpack-plugin@^4.4.1, copy-webpack-plugin@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/copy-webpack-plugin/-/copy-webpack-plugin-4.5.1.tgz#fc4f68f4add837cc5e13d111b20715793225d29c"
dependencies:
cacache "^10.0.4"
find-cache-dir "^1.0.0"
globby "^7.1.1"
is-glob "^4.0.0"
loader-utils "^1.1.0"
minimatch "^3.0.4"
p-limit "^1.0.0"
serialize-javascript "^1.4.0"
core-js@^1.0.0: core-js@^1.0.0:
version "1.2.7" version "1.2.7"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636" resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
@ -1586,6 +1612,13 @@ diffie-hellman@^5.0.0:
miller-rabin "^4.0.0" miller-rabin "^4.0.0"
randombytes "^2.0.0" randombytes "^2.0.0"
dir-glob@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-2.0.0.tgz#0b205d2b6aef98238ca286598a8204d29d0a0034"
dependencies:
arrify "^1.0.1"
path-type "^3.0.0"
dns-equal@^1.0.0: dns-equal@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/dns-equal/-/dns-equal-1.0.0.tgz#b39e7f1da6eb0a75ba9c17324b34753c47e0654d" resolved "https://registry.yarnpkg.com/dns-equal/-/dns-equal-1.0.0.tgz#b39e7f1da6eb0a75ba9c17324b34753c47e0654d"
@ -2171,6 +2204,17 @@ globby@^6.1.0:
pify "^2.0.0" pify "^2.0.0"
pinkie-promise "^2.0.0" pinkie-promise "^2.0.0"
globby@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/globby/-/globby-7.1.1.tgz#fb2ccff9401f8600945dfada97440cca972b8680"
dependencies:
array-union "^1.0.1"
dir-glob "^2.0.0"
glob "^7.1.2"
ignore "^3.3.5"
pify "^3.0.0"
slash "^1.0.0"
graceful-fs@^4.1.11, graceful-fs@^4.1.2: graceful-fs@^4.1.11, graceful-fs@^4.1.2:
version "4.1.11" version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
@ -2316,6 +2360,22 @@ html-minifier@^3.2.3, html-minifier@^3.5.8:
relateurl "0.2.x" relateurl "0.2.x"
uglify-js "3.3.x" uglify-js "3.3.x"
html-webpack-externals-plugin@^3.8.0:
version "3.8.0"
resolved "https://registry.yarnpkg.com/html-webpack-externals-plugin/-/html-webpack-externals-plugin-3.8.0.tgz#e3f38419c67b7599e69afab0966a2164d2a3d838"
dependencies:
ajv "^6.1.1"
copy-webpack-plugin "^4.4.1"
html-webpack-include-assets-plugin "^1.0.2"
html-webpack-include-assets-plugin@^1.0.2:
version "1.0.4"
resolved "https://registry.yarnpkg.com/html-webpack-include-assets-plugin/-/html-webpack-include-assets-plugin-1.0.4.tgz#279cfdf001301f5a945b2525f7f6394d48a3a157"
dependencies:
glob "^7.1.2"
minimatch "^3.0.4"
slash "^1.0.0"
html-webpack-plugin@^3.2.0: html-webpack-plugin@^3.2.0:
version "3.2.0" version "3.2.0"
resolved "https://registry.yarnpkg.com/html-webpack-plugin/-/html-webpack-plugin-3.2.0.tgz#b01abbd723acaaa7b37b6af4492ebda03d9dd37b" resolved "https://registry.yarnpkg.com/html-webpack-plugin/-/html-webpack-plugin-3.2.0.tgz#b01abbd723acaaa7b37b6af4492ebda03d9dd37b"
@ -2416,7 +2476,7 @@ ignore-walk@^3.0.1:
dependencies: dependencies:
minimatch "^3.0.4" minimatch "^3.0.4"
ignore@^3.3.7: ignore@^3.3.5, ignore@^3.3.7:
version "3.3.8" version "3.3.8"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.8.tgz#3f8e9c35d38708a3a7e0e9abb6c73e7ee7707b2b" resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.8.tgz#3f8e9c35d38708a3a7e0e9abb6c73e7ee7707b2b"
@ -2746,6 +2806,10 @@ json-schema-traverse@^0.3.0:
version "0.3.1" version "0.3.1"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340" resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340"
json-schema-traverse@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
json3@^3.3.2: json3@^3.3.2:
version "3.3.2" version "3.3.2"
resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1" resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1"
@ -3384,6 +3448,12 @@ p-finally@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
p-limit@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8"
dependencies:
p-try "^1.0.0"
p-limit@^1.1.0: p-limit@^1.1.0:
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c"
@ -3498,6 +3568,12 @@ path-type@^1.0.0:
pify "^2.0.0" pify "^2.0.0"
pinkie-promise "^2.0.0" pinkie-promise "^2.0.0"
path-type@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
dependencies:
pify "^3.0.0"
pbkdf2@^3.0.3: pbkdf2@^3.0.3:
version "3.0.16" version "3.0.16"
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.16.tgz#7404208ec6b01b62d85bf83853a8064f8d9c2a5c" resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.16.tgz#7404208ec6b01b62d85bf83853a8064f8d9c2a5c"

Loading…
Cancel
Save