Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

using webpack

goenningcf17bc1257fb
diff --git a/.gitignore b/.gitignore
index 180c0e21a..7cb42ef30 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
vendor/*/
data/
tmp/
+dist/
node_modules/
*.coverprofile
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 66464901f..83181277e 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -13,7 +13,8 @@
"wechy.exe": true,
"tmp": true,
"vendor": true,
- "node_modules": true
+ "node_modules": true,
+ "dist": true
},
"vsicons.presets.angular": true
}
\ No newline at end of file
diff --git a/app/renderer.go b/app/renderer.go
index 4e0dc306f..045977039 100644
--- a/app/renderer.go
+++ b/app/renderer.go
@@ -9,6 +9,8 @@ import (
"os"
+ "io/ioutil"
+
"github.com/WeCanHearYou/wechy/identity"
"github.com/WeCanHearYou/wechy/toolbox/env"
"github.com/labstack/echo"
@@ -78,6 +80,9 @@ func (r *HTMLRenderer) Render(w io.Writer, name string, data interface{}, c echo
}
m["CurrentUrl"] = protocol + c.Request().Host + c.Request().URL.String()
+ files, _ := ioutil.ReadDir("dist/js")
+ m["JavaScriptBundle"] = files[0].Name()
+
return tmpl.Execute(w, m)
}
diff --git a/app/router.go b/app/router.go
index 7df499fda..baca5e966 100644
--- a/app/router.go
+++ b/app/router.go
@@ -59,8 +59,7 @@ func GetMainEngine(ctx *WechyServices) *echo.Echo {
router.HTTPErrorHandler = errorHandler
router.Static("/favicon.ico", "public/imgs/favicon.ico")
- router.Static("/public", "public")
- router.Static("/assets", "node_modules") //TODO: Don't expose node_modules
+ router.Static("/assets", "dist")
authGroup := router.Group("", identity.HostChecker(env.MustGet("AUTH_ENDPOINT")))
{
diff --git a/assets.json b/assets.json
new file mode 100644
index 000000000..1f0704c9d
--- /dev/null
+++ b/assets.json
@@ -0,0 +1 @@
+4390ad7f630f41e4b096
\ No newline at end of file
diff --git a/package.json b/package.json
index 4073c461c..5db9f9122 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,20 @@
"version": "0.0.0",
"repository": "https://github.com/WeCanHearYou/wechy",
"license": "GPL-3.0",
+ "scripts": {
+ "build": "rm -rf assets && webpack",
+ "postinstall": "npm run build"
+ },
"dependencies": {
- "semantic-ui-css": "^2.2.4"
+ "semantic-ui-css": "^2.2.9"
+ },
+ "devDependencies": {
+ "@types/jquery": "^2.0.41",
+ "css-loader": "^0.27.3",
+ "file-loader": "^0.10.1",
+ "style-loader": "^0.13.2",
+ "ts-loader": "^2.0.1",
+ "typescript": "^2.2.1",
+ "webpack": "^2.2.1"
}
}
diff --git a/public/index.ts b/public/index.ts
new file mode 100644
index 000000000..ae1c91a92
--- /dev/null
+++ b/public/index.ts
@@ -0,0 +1,39 @@
+import * as $ from "jquery";
+
+(<any>window).$ = (<any>window).jQuery = $;
+import "semantic-ui-css/semantic.min.css";
+import "./css/main.css";
+import "semantic-ui-css/semantic.min.js";
+
+$(document).ready(() => {
+ console.log("It works 3.");
+ $(".ui.dropdown").dropdown();
+
+ $('.menu .signin').popup({
+ inline: true,
+ hoverable: true,
+ popup: '#user-popup',
+ position : 'bottom right',
+ delay: {
+ show: 300
+ }
+ });
+
+ $('#user-popup a').click(function() {
+ $(this).addClass("loading");
+ });
+
+ var input = <HTMLInputElement>document.querySelector("#new-idea-input");
+ var submit = <HTMLElement>document.querySelector("#new-idea-submit");
+
+ submit.style.display = 'none';
+
+ input.addEventListener("keyup", function() {
+ if (this.value) {
+ submit.style.display = 'block';
+ } else {
+ submit.style.display = 'none';
+ }
+ });
+});
+
diff --git a/public/js/main.js b/public/js/main.js
deleted file mode 100644
index cbc0cedab..000000000
--- a/public/js/main.js
+++ /dev/null
@@ -1,29 +0,0 @@
-document.addEventListener("DOMContentLoaded", function() {
- $('.ui.dropdown').dropdown();
- $('.menu .signin').popup({
- inline: true,
- hoverable: true,
- popup: '#user-popup',
- position : 'bottom right',
- delay: {
- show: 300
- }
- });
-
- $('#user-popup a').click(function() {
- $(this).addClass("loading");
- });
-
- var input = document.querySelector("#new-idea-input");
- var submit = document.querySelector("#new-idea-submit");
-
- submit.style.display = 'none';
-
- input.addEventListener("keyup", function() {
- if (this.value) {
- submit.style.display = 'block';
- } else {
- submit.style.display = 'none';
- }
- });
-});
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
new file mode 100755
index 000000000..484cf8513
--- /dev/null
+++ b/tsconfig.json
@@ -0,0 +1,9 @@
+{
+ "compilerOptions": {
+ "module": "commonjs",
+ "target": "es5",
+ "noImplicitAny": true,
+ "strictNullChecks": true,
+ "sourceMap": true
+ }
+}
\ No newline at end of file
diff --git a/views/base.html b/views/base.html
index aab73e7ab..75ca354bf 100644
--- a/views/base.html
+++ b/views/base.html
@@ -3,12 +3,8 @@
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1">
- <link rel="stylesheet" type="text/css" href="/assets/semantic-ui-css/semantic.min.css">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
- <link rel="stylesheet" type="text/css" href="/public/css/main.css">
- <script type="text/javascript" src="/assets/jquery/dist/jquery.min.js"></script>
- <script type="text/javascript" src="/assets/semantic-ui-css/semantic.min.js"></script>
- <script type="text/javascript" src="/public/js/main.js"></script>
+ <script type="text/javascript" src="/assets/js/{{ .JavaScriptBundle }}"></script>
<title>{{template "title" .}}</title>
</head>
<body>
diff --git a/webpack.config.js b/webpack.config.js
new file mode 100755
index 000000000..1be982b29
--- /dev/null
+++ b/webpack.config.js
@@ -0,0 +1,24 @@
+const path = require('path');
+
+module.exports = {
+ entry: "./public/index.ts",
+ output: {
+ path: __dirname + '/dist',
+ filename: "js/bundle.[chunkhash].js",
+ publicPath: "/assets/"
+ },
+ module: {
+ loaders: [
+ { test: /\.css$/, loader: "style-loader!css-loader" },
+ { test: /\.ts$/, loader: "ts-loader" },
+ {
+ test: /\.(eot|svg|ttf|woff|woff2)$/,
+ loader: 'file-loader?name=fonts/[name].[hash].[ext]'
+ },
+ {
+ test: /\.(png|gif|jpg|jpeg)$/,
+ loader: 'file-loader?name=images/[name].[hash].[ext]'
+ }
+ ]
+ }
+};
\ No newline at end of file