2018-09-15 00:32:30 +03:00
|
|
|
// Variables in .env and .env.defaults will be added to process.env
|
|
|
|
const dotenv = require("dotenv");
|
2019-05-01 00:20:49 +03:00
|
|
|
|
2018-09-15 00:32:30 +03:00
|
|
|
if (process.env.NODE_ENV === "production") {
|
|
|
|
dotenv.config({ path: ".env.prod" });
|
2019-05-10 00:21:45 +03:00
|
|
|
} else if (process.env.NODE_ENV === "test") {
|
|
|
|
dotenv.config({ path: ".env.test" });
|
2018-09-15 00:32:30 +03:00
|
|
|
} else {
|
|
|
|
dotenv.config({ path: ".env" });
|
|
|
|
dotenv.config({ path: ".env.defaults" });
|
|
|
|
}
|
|
|
|
|
2019-03-09 02:31:08 +03:00
|
|
|
const fs = require("fs");
|
|
|
|
const selfsigned = require("selfsigned");
|
|
|
|
const cors = require("cors");
|
2018-05-29 04:35:21 +03:00
|
|
|
const HTMLWebpackPlugin = require("html-webpack-plugin");
|
2018-09-12 07:31:16 +03:00
|
|
|
const path = require("path");
|
|
|
|
const webpack = require("webpack");
|
2019-04-04 03:29:39 +03:00
|
|
|
const TerserJSPlugin = require("terser-webpack-plugin");
|
|
|
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
|
|
|
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
2018-05-29 04:35:21 +03:00
|
|
|
|
2019-03-09 02:31:08 +03:00
|
|
|
function createHTTPSConfig() {
|
|
|
|
// Generate certs for the local webpack-dev-server.
|
|
|
|
if (fs.existsSync(path.join(__dirname, "certs"))) {
|
|
|
|
const key = fs.readFileSync(path.join(__dirname, "certs", "key.pem"));
|
|
|
|
const cert = fs.readFileSync(path.join(__dirname, "certs", "cert.pem"));
|
|
|
|
|
|
|
|
return { key, cert };
|
|
|
|
} else {
|
|
|
|
const pems = selfsigned.generate(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: "commonName",
|
|
|
|
value: "localhost"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{
|
|
|
|
days: 365,
|
|
|
|
algorithm: "sha256",
|
|
|
|
extensions: [
|
|
|
|
{
|
|
|
|
name: "subjectAltName",
|
|
|
|
altNames: [
|
|
|
|
{
|
|
|
|
type: 2,
|
|
|
|
value: "localhost"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 2,
|
|
|
|
value: "hubs.local"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
fs.mkdirSync(path.join(__dirname, "certs"));
|
|
|
|
fs.writeFileSync(path.join(__dirname, "certs", "cert.pem"), pems.cert);
|
|
|
|
fs.writeFileSync(path.join(__dirname, "certs", "key.pem"), pems.private);
|
|
|
|
|
|
|
|
return {
|
|
|
|
key: pems.private,
|
|
|
|
cert: pems.cert
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultHostName = "hubs.local";
|
|
|
|
const host = process.env.HOST_IP || defaultHostName;
|
2019-05-10 00:21:45 +03:00
|
|
|
const port = process.env.HOST_PORT || 9090;
|
2019-03-09 02:31:08 +03:00
|
|
|
|
2019-04-04 21:47:49 +03:00
|
|
|
module.exports = env => {
|
2019-05-01 02:10:25 +03:00
|
|
|
return {
|
2019-04-04 21:47:49 +03:00
|
|
|
entry: {
|
|
|
|
entry: ["./src/index.js"]
|
|
|
|
},
|
2018-05-29 04:35:21 +03:00
|
|
|
|
2019-04-04 21:47:49 +03:00
|
|
|
devtool: process.env.NODE_ENV === "production" ? "source-map" : "inline-source-map",
|
2018-07-04 01:50:49 +03:00
|
|
|
|
2019-04-04 21:47:49 +03:00
|
|
|
devServer: {
|
|
|
|
https: createHTTPSConfig(),
|
|
|
|
historyApiFallback: true,
|
2019-05-10 00:21:45 +03:00
|
|
|
port,
|
2019-04-04 21:47:49 +03:00
|
|
|
host: process.env.HOST_IP || "0.0.0.0",
|
2019-05-10 00:21:45 +03:00
|
|
|
public: `${host}:${port}`,
|
2019-04-04 21:47:49 +03:00
|
|
|
publicPath: process.env.BASE_ASSETS_PATH || "",
|
|
|
|
useLocalIp: true,
|
|
|
|
allowedHosts: [host],
|
|
|
|
headers: {
|
|
|
|
"Access-Control-Allow-Origin": "*"
|
|
|
|
},
|
|
|
|
before: function(app) {
|
|
|
|
// be flexible with people accessing via a local reticulum on another port
|
|
|
|
app.use(cors({ origin: /hubs\.local(:\d*)?$/ }));
|
|
|
|
}
|
2019-03-09 02:31:08 +03:00
|
|
|
},
|
|
|
|
|
2019-04-04 21:47:49 +03:00
|
|
|
output: {
|
|
|
|
filename: "assets/js/[name]-[chunkhash].js",
|
|
|
|
publicPath: process.env.BASE_ASSETS_PATH || "/"
|
|
|
|
},
|
2018-05-29 04:35:21 +03:00
|
|
|
|
2019-04-04 21:47:49 +03:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg|jpeg|gif|svg)(\?.*$|$)/,
|
|
|
|
use: {
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "[name]-[hash].[ext]",
|
|
|
|
outputPath: "assets/images"
|
|
|
|
}
|
2019-04-03 03:32:52 +03:00
|
|
|
}
|
2019-04-04 21:47:49 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff|woff2|ttf|eot)(\?.*$|$)/,
|
|
|
|
use: {
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "[name]-[hash].[ext]",
|
|
|
|
outputPath: "assets/fonts"
|
|
|
|
}
|
2019-04-03 03:32:52 +03:00
|
|
|
}
|
2019-04-04 21:47:49 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(glb)(\?.*$|$)/,
|
|
|
|
use: {
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "[name]-[hash].[ext]",
|
|
|
|
outputPath: "assets/models"
|
|
|
|
}
|
2019-04-04 03:29:39 +03:00
|
|
|
}
|
2019-04-04 21:47:49 +03:00
|
|
|
},
|
2019-09-21 22:29:56 +03:00
|
|
|
{
|
|
|
|
test: /\.(gltf)(\?.*$|$)/,
|
|
|
|
use: {
|
|
|
|
loader: "gltf-webpack-loader",
|
|
|
|
options: {
|
|
|
|
name: "[name]-[hash].[ext]",
|
|
|
|
outputPath: "assets/models"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(bin)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "[name]-[hash].[ext]",
|
|
|
|
outputPath: "assets/models"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2019-04-04 21:47:49 +03:00
|
|
|
{
|
|
|
|
test: /\.(mp4|webm)(\?.*$|$)/,
|
|
|
|
use: {
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "[name]-[hash].[ext]",
|
|
|
|
outputPath: "assets/videos"
|
|
|
|
}
|
2019-04-04 03:29:39 +03:00
|
|
|
}
|
2019-04-04 21:47:49 +03:00
|
|
|
},
|
2019-04-25 05:20:46 +03:00
|
|
|
{
|
|
|
|
test: /\.(spoke)(\?.*$|$)/,
|
|
|
|
use: {
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "[name]-[hash].[ext]",
|
|
|
|
outputPath: "assets/templates"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-04-04 21:47:49 +03:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
include: path.join(__dirname, "src"),
|
|
|
|
use: "babel-loader"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.worker\.js$/,
|
|
|
|
include: path.join(__dirname, "src"),
|
|
|
|
loader: "worker-loader",
|
2019-04-03 03:32:52 +03:00
|
|
|
options: {
|
2019-05-03 01:14:54 +03:00
|
|
|
// Workers must be inlined because they are hosted on a CDN and CORS doesn't permit us
|
|
|
|
// from loading worker scripts from another origin. To minimize bundle size, dynamically
|
|
|
|
// import a wrapper around the worker. See SketchfabZipLoader.js and API.js for an example.
|
2019-05-03 00:22:08 +03:00
|
|
|
name: "assets/js/workers/[name]-[hash].js",
|
2019-05-03 01:14:54 +03:00
|
|
|
inline: true,
|
|
|
|
fallback: false
|
2019-04-04 21:47:49 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.wasm$/,
|
|
|
|
type: "javascript/auto",
|
|
|
|
use: {
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
outputPath: "assets/js/wasm",
|
|
|
|
name: "[name]-[hash].[ext]"
|
|
|
|
}
|
2019-04-03 03:32:52 +03:00
|
|
|
}
|
|
|
|
}
|
2019-04-04 21:47:49 +03:00
|
|
|
]
|
|
|
|
},
|
2018-05-29 04:35:21 +03:00
|
|
|
|
2019-05-02 21:16:31 +03:00
|
|
|
target: "web",
|
|
|
|
node: {
|
|
|
|
__dirname: false,
|
|
|
|
fs: "empty",
|
|
|
|
Buffer: false,
|
|
|
|
process: false
|
|
|
|
},
|
|
|
|
|
2019-04-04 21:47:49 +03:00
|
|
|
optimization: {
|
2019-09-10 18:30:26 +03:00
|
|
|
minimizer: [new TerserJSPlugin({ sourceMap: true, parallel: true, cache: path.join(__dirname, ".tersercache") })]
|
2019-04-04 21:47:49 +03:00
|
|
|
},
|
2019-04-04 03:29:39 +03:00
|
|
|
|
2019-04-04 21:47:49 +03:00
|
|
|
plugins: [
|
|
|
|
new BundleAnalyzerPlugin({
|
|
|
|
analyzerMode: env && env.BUNDLE_ANALYZER ? "server" : "disabled"
|
|
|
|
}),
|
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{
|
2019-11-19 23:59:59 +03:00
|
|
|
from: path.join(
|
|
|
|
__dirname,
|
|
|
|
"src",
|
|
|
|
"assets",
|
|
|
|
process.env.IS_MOZ === "true" ? "favicon-spoke.ico" : "favicon-editor.ico"
|
|
|
|
),
|
|
|
|
to: "assets/images/favicon.ico"
|
2019-04-04 21:47:49 +03:00
|
|
|
}
|
|
|
|
]),
|
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{
|
|
|
|
from: path.join(__dirname, "src", "assets", "favicon-spoke.ico"),
|
|
|
|
to: "assets/images/favicon-spoke.ico"
|
|
|
|
}
|
|
|
|
]),
|
2019-12-30 22:02:19 +03:00
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{
|
|
|
|
from: path.join(__dirname, "src", "assets", "favicon-editor.ico"),
|
|
|
|
to: "assets/images/favicon-editor.ico"
|
|
|
|
}
|
|
|
|
]),
|
2019-04-04 21:47:49 +03:00
|
|
|
new HTMLWebpackPlugin({
|
|
|
|
template: path.join(__dirname, "src", "index.html"),
|
2019-11-19 23:59:59 +03:00
|
|
|
faviconPath: (process.env.BASE_ASSETS_PATH || "/") + "assets/images/favicon.ico"
|
2019-04-04 21:47:49 +03:00
|
|
|
}),
|
|
|
|
new webpack.EnvironmentPlugin({
|
2019-05-01 02:10:25 +03:00
|
|
|
BUILD_VERSION: "dev",
|
2019-04-04 21:47:49 +03:00
|
|
|
NODE_ENV: "development",
|
|
|
|
RETICULUM_SERVER: undefined,
|
2019-09-11 00:39:22 +03:00
|
|
|
THUMBNAIL_SERVER: "",
|
2019-04-04 21:47:49 +03:00
|
|
|
HUBS_SERVER: undefined,
|
|
|
|
CORS_PROXY_SERVER: null,
|
|
|
|
BASE_ASSETS_PATH: "",
|
|
|
|
NON_CORS_PROXY_DOMAINS: "",
|
2019-05-01 00:20:49 +03:00
|
|
|
ROUTER_BASE_PATH: "",
|
2019-08-09 23:02:25 +03:00
|
|
|
SENTRY_DSN: null,
|
2019-10-31 01:47:16 +03:00
|
|
|
GA_TRACKING_ID: null,
|
2019-11-20 00:48:36 +03:00
|
|
|
IS_MOZ: false,
|
2019-08-09 23:02:25 +03:00
|
|
|
GITHUB_ORG: "mozilla",
|
|
|
|
GITHUB_REPO: "spoke",
|
|
|
|
GITHUB_PUBLIC_TOKEN: "de8cbfb4cc0281c7b731c891df431016c29b0ace"
|
2019-04-04 21:47:49 +03:00
|
|
|
})
|
|
|
|
]
|
|
|
|
};
|
|
|
|
};
|