Skip to content

Commit 33a3d56

Browse files
committed
Improved npm scripts
1 parent 7619437 commit 33a3d56

13 files changed

+2830
-1051
lines changed

.env.defaults renamed to .defaults.env

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# To override these variables, create a .env file containing the overrides.
2+
23
# Domain for short links
34
SHORTLINK_DOMAIN="hub.link"
45

@@ -19,17 +20,12 @@ ASSET_BUNDLE_SERVER="https://asset-bundles-prod.reticulum.io"
1920
# Comma-separated list of domains which are known to not need CORS proxying
2021
NON_CORS_PROXY_DOMAINS="hubs.local,dev.reticulum.io"
2122

22-
# A comma-separated list of environment URLs to make available in the picker, besides the defaults.
23-
# These URLs are expected to be relative to ASSET_BUNDLE_SERVER.
24-
EXTRA_ENVIRONMENTS=
25-
2623
# The root URL under which Hubs expects static assets to be served.
2724
BASE_ASSETS_PATH=/
2825

29-
# This origin trial token is used to enable WebVR in Android Chrome for hubs.mozilla.com.
30-
# You can find more information about getting your own origin trial token here:
31-
# https://github.com/GoogleChrome/OriginTrials/blob/gh-pages/developer-guide.md
32-
ORIGIN_TRIAL_TOKEN="AtOSmCIwReA1cq9L756ii6hccpiM4ObrwF0bYDmr1nNzMQi2zTjoN1puufPHt+QUwcx0F6rbLEPj/YrQanRQUA8AAABVeyJvcmlnaW4iOiJodHRwczovL2h1YnMubW96aWxsYS5jb206NDQzIiwiZmVhdHVyZSI6IldlYlZSMS4xTTYyIiwiZXhwaXJ5IjoxNTM2NjI0MDAwfQ=="
33-
ORIGIN_TRIAL_EXPIRES="2018-09-11"
34-
26+
# The default scene to use. Note the example scene id is only availible on dev.reticulum.io
3527
DEFAULT_SCENE_SID="JGLt8DP"
28+
29+
# Uncomment to load the app config from the reticulum server in development.
30+
# Useful when testing the admin panel.
31+
# LOAD_APP_CONFIG=true
File renamed without changes.

admin/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"url": "https://github.com/mozilla/hubs.git"
1010
},
1111
"scripts": {
12-
"start": "webpack-dev-server --mode=development",
12+
"start": "webpack-dev-server --mode=development --env.hubsCloudDev",
13+
"dev": "webpack-dev-server --mode=development --env.dev",
14+
"local": "webpack-dev-server --mode=development --env.local",
1315
"build": "rimraf ./dist && webpack --mode=production",
1416
"prettier": "prettier --write '*.js' 'src/**/*.js'",
1517
"lint:js": "eslint '*.js' 'src/**/*.js'",

admin/scripts/run-local-reticulum.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

admin/webpack.config.js

Lines changed: 166 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// Variables in .env and .env.defaults will be added to process.env
21
const dotenv = require("dotenv");
3-
dotenv.config({ path: ".env" });
4-
dotenv.config({ path: ".env.defaults" });
5-
62
const fs = require("fs");
73
const path = require("path");
84
const selfsigned = require("selfsigned");
@@ -59,148 +55,179 @@ function createHTTPSConfig() {
5955
}
6056
}
6157

62-
const defaultHostName = "hubs.local";
63-
const host = process.env.HOST_IP || defaultHostName;
64-
const babelConfig = JSON.parse(fs.readFileSync(path.resolve(__dirname, ".babelrc")).toString());
58+
module.exports = (env, argv) => {
59+
env = env || {};
60+
61+
// Load environment variables from .env files.
62+
// .env takes precedent over .defaults.env
63+
// Previously defined environment variables are not overwritten
64+
dotenv.config({ path: ".env" });
65+
dotenv.config({ path: ".defaults.env" });
66+
67+
if (env.local) {
68+
Object.assign(process.env, {
69+
HOST: "hubs.local",
70+
CORS_PROXY_HOST: "hubs-proxy.local",
71+
RETICULUM_SOCKET_SERVER: "hubs.local",
72+
CORS_PROXY_SERVER: "hubs-proxy.local:4000",
73+
NON_CORS_PROXY_DOMAINS: "hubs.local,dev.reticulum.io",
74+
BASE_ASSETS_PATH: "https://hubs.local:8080/",
75+
RETICULUM_SERVER: "hubs.local:4000",
76+
POSTGREST_SERVER: "",
77+
ITA_SERVER: ""
78+
});
79+
}
6580

66-
module.exports = (env, argv) => ({
67-
node: {
68-
fs: "empty"
69-
},
70-
entry: {
71-
admin: path.join(__dirname, "src", "admin.js")
72-
},
73-
output: {
74-
filename: "assets/js/[name]-[chunkhash].js",
75-
publicPath: process.env.BASE_ASSETS_PATH || ""
76-
},
77-
devtool: argv.mode === "production" ? "source-map" : "inline-source-map",
78-
devServer: {
79-
https: createHTTPSConfig(),
80-
host: process.env.HOST_IP || "0.0.0.0",
81-
port: process.env.PORT || "8989",
82-
public: `${host}:${process.env.PORT || "8989"}`,
83-
useLocalIp: true,
84-
allowedHosts: [host],
85-
headers: {
86-
"Access-Control-Allow-Origin": "*"
81+
const defaultHostName = "hubs.local";
82+
const host = process.env.HOST_IP || defaultHostName;
83+
84+
// Remove comments from .babelrc
85+
const babelConfig = JSON.parse(
86+
fs
87+
.readFileSync(path.resolve(__dirname, ".babelrc"))
88+
.toString()
89+
.replace(/\/\/.+/g, "")
90+
);
91+
92+
return {
93+
node: {
94+
fs: "empty"
8795
},
88-
before: function(app) {
89-
// be flexible with people accessing via a local reticulum on another port
90-
app.use(cors({ origin: /hubs\.local(:\d*)?$/ }));
91-
// networked-aframe makes HEAD requests to the server for time syncing. Respond with an empty body.
92-
app.head("*", function(req, res, next) {
93-
if (req.method === "HEAD") {
94-
res.append("Date", new Date().toGMTString());
95-
res.send("");
96-
} else {
97-
next();
98-
}
99-
});
100-
}
101-
},
102-
performance: {
103-
// Ignore media and sourcemaps when warning about file size.
104-
assetFilter(assetFilename) {
105-
return !/\.(map|png|jpg|gif|glb|webm)$/.test(assetFilename);
106-
}
107-
},
108-
module: {
109-
rules: [
110-
{
111-
test: /\.html$/,
112-
loader: "html-loader"
113-
},
114-
{
115-
test: /\.js$/,
116-
loader: "babel-loader",
117-
options: babelConfig,
118-
exclude: function(modulePath) {
119-
return /node_modules/.test(modulePath) && !/node_modules\/hubs/.test(modulePath);
120-
}
121-
},
122-
{
123-
test: /\.worker\.js$/,
124-
loader: "worker-loader",
125-
options: {
126-
name: "assets/js/[name]-[hash].js",
127-
publicPath: "/",
128-
inline: true
129-
}
96+
entry: {
97+
admin: path.join(__dirname, "src", "admin.js")
98+
},
99+
output: {
100+
filename: "assets/js/[name]-[chunkhash].js",
101+
publicPath: process.env.BASE_ASSETS_PATH || ""
102+
},
103+
devtool: argv.mode === "production" ? "source-map" : "inline-source-map",
104+
devServer: {
105+
https: createHTTPSConfig(),
106+
host: process.env.HOST_IP || "0.0.0.0",
107+
port: process.env.PORT || "8989",
108+
public: `${host}:${process.env.PORT || "8989"}`,
109+
useLocalIp: true,
110+
allowedHosts: [host],
111+
headers: {
112+
"Access-Control-Allow-Origin": "*"
130113
},
131-
{
132-
test: /\.(scss|css)$/,
133-
use: [
134-
{
135-
loader: MiniCssExtractPlugin.loader
136-
},
137-
{
138-
loader: "css-loader",
114+
before: function(app) {
115+
// be flexible with people accessing via a local reticulum on another port
116+
app.use(cors({ origin: /hubs\.local(:\d*)?$/ }));
117+
// networked-aframe makes HEAD requests to the server for time syncing. Respond with an empty body.
118+
app.head("*", function(req, res, next) {
119+
if (req.method === "HEAD") {
120+
res.append("Date", new Date().toGMTString());
121+
res.send("");
122+
} else {
123+
next();
124+
}
125+
});
126+
}
127+
},
128+
performance: {
129+
// Ignore media and sourcemaps when warning about file size.
130+
assetFilter(assetFilename) {
131+
return !/\.(map|png|jpg|gif|glb|webm)$/.test(assetFilename);
132+
}
133+
},
134+
module: {
135+
rules: [
136+
{
137+
test: /\.html$/,
138+
loader: "html-loader"
139+
},
140+
{
141+
test: /\.js$/,
142+
loader: "babel-loader",
143+
options: babelConfig,
144+
exclude: function(modulePath) {
145+
return /node_modules/.test(modulePath) && !/node_modules\/hubs/.test(modulePath);
146+
}
147+
},
148+
{
149+
test: /\.worker\.js$/,
150+
loader: "worker-loader",
151+
options: {
152+
name: "assets/js/[name]-[hash].js",
153+
publicPath: "/",
154+
inline: true
155+
}
156+
},
157+
{
158+
test: /\.(scss|css)$/,
159+
use: [
160+
{
161+
loader: MiniCssExtractPlugin.loader
162+
},
163+
{
164+
loader: "css-loader",
165+
options: {
166+
name: "[path][name]-[hash].[ext]",
167+
localIdentName: "[name]__[local]__[hash:base64:5]",
168+
camelCase: true
169+
}
170+
},
171+
"sass-loader"
172+
]
173+
},
174+
{
175+
test: /\.(glsl|frag|vert)$/,
176+
use: { loader: "raw-loader" }
177+
},
178+
{
179+
test: /\.(png|jpg|gif|glb|ogg|mp3|mp4|wav|woff2|svg|webm)$/,
180+
use: {
181+
loader: "file-loader",
139182
options: {
183+
// move required assets to output dir and add a hash for cache busting
140184
name: "[path][name]-[hash].[ext]",
141-
localIdentName: "[name]__[local]__[hash:base64:5]",
142-
camelCase: true
185+
// Make asset paths relative to /src
186+
context: path.join(__dirname, "src")
143187
}
144-
},
145-
"sass-loader"
146-
]
147-
},
148-
{
149-
test: /\.(glsl|frag|vert)$/,
150-
use: { loader: "raw-loader" }
151-
},
152-
{
153-
test: /\.(png|jpg|gif|glb|ogg|mp3|mp4|wav|woff2|svg|webm)$/,
154-
use: {
155-
loader: "file-loader",
156-
options: {
157-
// move required assets to output dir and add a hash for cache busting
158-
name: "[path][name]-[hash].[ext]",
159-
// Make asset paths relative to /src
160-
context: path.join(__dirname, "src")
161188
}
162-
}
163-
},
164-
{
165-
test: /\.(wasm)$/,
166-
type: "javascript/auto",
167-
use: {
168-
loader: "file-loader",
169-
options: {
170-
outputPath: "assets/wasm",
171-
name: "[name]-[hash].[ext]"
189+
},
190+
{
191+
test: /\.(wasm)$/,
192+
type: "javascript/auto",
193+
use: {
194+
loader: "file-loader",
195+
options: {
196+
outputPath: "assets/wasm",
197+
name: "[name]-[hash].[ext]"
198+
}
172199
}
173200
}
174-
}
175-
]
176-
},
177-
plugins: [
178-
new HTMLWebpackPlugin({
179-
filename: "admin.html",
180-
template: path.join(__dirname, "src", "admin.html")
181-
}),
182-
new CopyWebpackPlugin([
183-
{
184-
from: "src/assets/images/favicon.ico",
185-
to: "favicon.ico"
186-
}
187-
]),
188-
// Extract required css and add a content hash.
189-
new MiniCssExtractPlugin({
190-
filename: "assets/stylesheets/[name]-[contenthash].css",
191-
disable: argv.mode !== "production"
192-
}),
193-
// Define process.env variables in the browser context.
194-
new webpack.DefinePlugin({
195-
"process.env": JSON.stringify({
196-
NODE_ENV: argv.mode,
197-
BUILD_VERSION: process.env.BUILD_VERSION,
198-
CONFIGURABLE_SERVICES: process.env.CONFIGURABLE_SERVICES,
199-
ITA_SERVER: process.env.ITA_SERVER,
200-
RETICULUM_SERVER: process.env.RETICULUM_SERVER,
201-
CORS_PROXY_SERVER: process.env.CORS_PROXY_SERVER,
202-
POSTGREST_SERVER: process.env.POSTGREST_SERVER
201+
]
202+
},
203+
plugins: [
204+
new HTMLWebpackPlugin({
205+
filename: "admin.html",
206+
template: path.join(__dirname, "src", "admin.html")
207+
}),
208+
new CopyWebpackPlugin([
209+
{
210+
from: "src/assets/images/favicon.ico",
211+
to: "favicon.ico"
212+
}
213+
]),
214+
// Extract required css and add a content hash.
215+
new MiniCssExtractPlugin({
216+
filename: "assets/stylesheets/[name]-[contenthash].css",
217+
disable: argv.mode !== "production"
218+
}),
219+
// Define process.env variables in the browser context.
220+
new webpack.DefinePlugin({
221+
"process.env": JSON.stringify({
222+
NODE_ENV: argv.mode,
223+
BUILD_VERSION: process.env.BUILD_VERSION,
224+
CONFIGURABLE_SERVICES: process.env.CONFIGURABLE_SERVICES,
225+
ITA_SERVER: process.env.ITA_SERVER,
226+
RETICULUM_SERVER: process.env.RETICULUM_SERVER,
227+
CORS_PROXY_SERVER: process.env.CORS_PROXY_SERVER,
228+
POSTGREST_SERVER: process.env.POSTGREST_SERVER
229+
})
203230
})
204-
})
205-
]
206-
});
231+
]
232+
};
233+
};

0 commit comments

Comments
 (0)