Skip to content

Commit

Permalink
add launch.json
Browse files Browse the repository at this point in the history
  • Loading branch information
bitnimble committed Dec 17, 2022
1 parent 3cc54c9 commit 1ae812f
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 635 deletions.
78 changes: 74 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,83 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"compounds": [
{
"name": "Build + launch",
"configurations": ["Build", "Launch"],
"stopAll": true,
"presentation": {
"group": "main",
"order": 2
}
}
],
"configurations": [
{
"type": "pwa-chrome",
"name": "Build",
"type": "node",
"request": "launch",
"runtimeExecutable": "yarn",
"env": {
"NODE_ENV": "development",
},
"args": ["start", "${input:rememberProject}"],
"presentation": {
"group": "sub",
"order": 3
}
},
{
"name": "Launch",
"type": "chrome",
"url": "http://localhost:8080/static/",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
"presentation": {
"group": "sub",
"order": 3
}
},
{
"name": "Pick project",
"type": "node",
"request": "launch",
"runtimeExecutable": "echo",
"args": ["${input:selectProject}"],
"presentation": {
"group": "main",
"order": 1
}
},
],
"inputs": [
{
"id": "selectProject",
"type": "command",
"command": "extension.commandvariable.pickStringRemember",
"args": {
"description": "Pick a page to launch",
"options": [
["Re-launch most recently used page", "${remember:project}"],
["Pick page manually", "${pickFile:project}"],
],
"default": null,
"key": "project",
"pickFile": {
"project": {
"description": "Which page?",
"include": "src/pages/**/*.ts",
"showDirs": true,
"keyRemember": "project",
"display": "fileName"
}
}
}
},
{
"id": "rememberProject",
"type": "command",
"command": "extension.commandvariable.remember",
"args": { "key": "project" }
}
]
}
53 changes: 26 additions & 27 deletions config/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,32 @@ import { PageManifest } from './manifest';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import FontPreloadPlugin from 'webpack-font-preload-plugin';

const config = (env: any): Configuration & { devServer?: DevConfiguration } => {
const page = env.entry;
const proxying = !!env.proxying;
if (page == null) {
function getPageRoot(pageInput: string) {
const pageName = path.basename(pageInput);
try {
const manifest = require(path.resolve(__dirname, `../src/pages/${pageInput}/manifest.ts`));
return [manifest, path.resolve(__dirname, `../src/pages/${pageInput}`), pageName];
} catch (e) { }

try {
console.log('Could not resolve manifest in src/pages, attempting to resolve as an absolute path');
const manifest = require(path.resolve(`${pageInput}/manifest.ts`));
return [manifest, path.resolve(`${pageInput}`), pageName];
} catch (e) { }

throw new Error(`Could not find manifest.ts for page ${pageInput}`);
}

const config = (env: any): Configuration => {
if (env.entry == null) {
throw new Error('Page was not specified. Exiting.');
}

const devMode = env.mode === 'development';
console.log('Loading project manifest...')

let manifestFile: any;
let isExternalPage = false;
try {
// Try loading from pages folder
manifestFile = require(path.resolve(__dirname, `../src/pages/${page}/manifest.ts`));
} catch (e) {
console.error(e);
console.log(
'Could not resolve manifest in src/pages, attempting to resolve as a relative path',
);
// Try as a relative path instead
manifestFile = require(path.resolve(`${page}/manifest.ts`));
isExternalPage = true;
}
const devMode = env.mode === 'development';
const [manifestFile, pageRoot, pageName] = getPageRoot(env.entry);
console.log(`Loaded manifest from ${pageRoot}/manifest.ts`);
const manifest: PageManifest = manifestFile.manifest;
const fonts = manifest
.head
Expand All @@ -53,22 +56,18 @@ ${additionalTags}
`
: additionalTags;

const faviconPath = path.resolve(__dirname, `../src/pages/${page}/favicon.png`);
const faviconPath = path.resolve(`${pageRoot}/favicon.png`);

const modules = [
path.resolve(__dirname, '../node_modules'),
path.resolve(__dirname, `../src/pages/${page}/node_modules`),
path.resolve(`${pageRoot}/node_modules`),
path.resolve(__dirname, '../src'),
// Hack -- fix this
...(isExternalPage ? [path.resolve(page, '../')] : []),
];

return {
mode: devMode ? 'development' : 'production',
devtool: devMode && 'cheap-module-source-map',
entry: isExternalPage
? path.resolve(`${page}/index.tsx`)
: path.resolve(__dirname, `../src/pages/${page}/index.tsx`),
entry: path.resolve(`${pageRoot}/index.tsx`),
target: 'browserslist:> 0.5%, last 2 versions, Firefox ESR, not dead',
devServer: { historyApiFallback: true },
module: {
Expand Down Expand Up @@ -152,7 +151,7 @@ ${additionalTags}
output: {
filename: 'index.[contenthash].js',
publicPath: '/static/',
path: path.resolve(__dirname, `../dist/${page}/`),
path: path.resolve(__dirname, `../dist/${pageName}/`),
},
};
};
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@types/react": "^17.0.19",
"@types/react-dom": "^17.0.9",
"@types/terser-webpack-plugin": "^5.0.4",
"@types/webpack-dev-server": "^3.11.5",
"argv": "^0.0.2",
"autoprefixer": "^10.3.1",
"css-loader": "^6.2.0",
Expand All @@ -53,7 +52,7 @@
"typescript-plugin-css-modules": "^3.4.0",
"webpack": "^5.51.1",
"webpack-cli": "^4.8.0",
"webpack-dev-server": "^4.0.0",
"webpack-dev-server": "^4.11.1",
"webpack-font-preload-plugin": "^1.5.0"
}
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
"es2018",
"es2019",
"es2020",
"es2021",
"esnext"
],
"moduleResolution": "node",
"strict": true,
"target": "es6",
"target": "es2021",
"sourceMap": true,
"module": "commonjs",
"baseUrl": "src",
Expand Down
Loading

0 comments on commit 1ae812f

Please sign in to comment.