Skip to content

chore: FIT-14: Ensure production deployment of playground is resolvable as a subpath redirect #7595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions web/apps/playground/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"defaultConfiguration": "production",
"options": {
"compiler": "babel",
"outputPath": "dist/apps/playground",
"outputPath": "dist/apps/playground/playground-assets",
"index": "apps/playground/src/index.html",
"baseHref": "/",
"main": "apps/playground/src/main.tsx",
Expand All @@ -26,7 +26,8 @@
"extractLicenses": false,
"optimization": false,
"sourceMap": true,
"vendorChunk": true
"vendorChunk": true,
"baseHref": "/"
},
"production": {
"fileReplacements": [
Expand All @@ -39,7 +40,8 @@
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false
"vendorChunk": false,
"baseHref": "/playground-assets/"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"extract-antd-no-reset": "nx extract-antd-no-reset editor",
"storybook:serve": "nx storybook storybook",
"storybook:build": "nx build-storybook storybook",
"playground:serve": "FRONTEND_HOSTNAME=http://localhost:4200 MODE=standalone nx run playground:serve:development",
"playground:build": "NODE_ENV=production MODE=standalone nx run playground:build:production"
"playground:serve": "FRONTEND_HOSTNAME=http://localhost:4200 MODE=standalone-playground nx run playground:serve:development",
"playground:build": "NODE_ENV=production MODE=standalone-playground nx run playground:build:production && mv dist/apps/playground/playground-assets/index.html dist/apps/playground/index.html"
},
"husky": {
"hooks": {
Expand Down
68 changes: 36 additions & 32 deletions web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const optimizer = () => {
result.minimizer = undefined;
}

if (process.env.MODE === "standalone") {
if (process.env.MODE.startsWith("standalone")) {
result.runtimeChunk = false;
result.splitChunks = { cacheGroups: { default: false } };
}
Expand All @@ -84,7 +84,7 @@ module.exports = composePlugins(
withReact({ svgr: true }),
(config) => {
// LS entrypoint
if (process.env.MODE !== "standalone") {
if (!process.env.MODE.startsWith("standalone")) {
config.entry = {
main: {
import: path.resolve(__dirname, "apps/labelstudio/src/main.tsx"),
Expand All @@ -94,7 +94,12 @@ module.exports = composePlugins(
config.output = {
...config.output,
uniqueName: "labelstudio",
publicPath: isDevelopment && FRONTEND_HOSTNAME ? `${FRONTEND_HOSTNAME}/react-app/` : "auto",
publicPath:
isDevelopment && FRONTEND_HOSTNAME
? `${FRONTEND_HOSTNAME}/react-app/`
: process.env.MODE === "standalone-playground"
? "/playground-assets/"
: "auto",
scriptType: "text/javascript",
};

Expand Down Expand Up @@ -265,38 +270,37 @@ module.exports = composePlugins(
mode,
plugins,
optimization: optimizer(),
devServer:
process.env.MODE === "standalone"
? {}
: {
// Port for the Webpack dev server
port: HMR_PORT,
// Enable HMR
hot: true,
// Allow cross-origin requests from Django
headers: { "Access-Control-Allow-Origin": "*" },
static: {
directory: path.resolve(__dirname, "../label_studio/core/static/"),
publicPath: "/static/",
},
devMiddleware: {
publicPath: `${FRONTEND_HOSTNAME}/react-app/`,
devServer: process.env.MODE.startsWith("standalone")
? {}
: {
// Port for the Webpack dev server
port: HMR_PORT,
// Enable HMR
hot: true,
// Allow cross-origin requests from Django
headers: { "Access-Control-Allow-Origin": "*" },
static: {
directory: path.resolve(__dirname, "../label_studio/core/static/"),
publicPath: "/static/",
},
devMiddleware: {
publicPath: `${FRONTEND_HOSTNAME}/react-app/`,
},
allowedHosts: "all", // Allow access from Django's server
proxy: {
"/api": {
target: `${DJANGO_HOSTNAME}/api`,
changeOrigin: true,
pathRewrite: { "^/api": "" },
secure: false,
},
allowedHosts: "all", // Allow access from Django's server
proxy: {
"/api": {
target: `${DJANGO_HOSTNAME}/api`,
changeOrigin: true,
pathRewrite: { "^/api": "" },
secure: false,
},
"/": {
target: `${DJANGO_HOSTNAME}`,
changeOrigin: true,
secure: false,
},
"/": {
target: `${DJANGO_HOSTNAME}`,
changeOrigin: true,
secure: false,
},
},
},
});
},
);
Loading