Skip to content
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

Add SolidJS #9

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dotnet restore
dotnet build
dotnet pack -c=Release // Prints the path to the nupkg

dotnet install -i <path/to/the/nupkg>
dotnet new --install <path/to/the/nupkg>
```

## Usage
Expand All @@ -35,6 +35,20 @@ dotnet new vite -o my-vite-project --frontendFramework vue --useTypeScript
dotnet new vite -o my-vite-project -f vue -t
```


It is posible to create a new project that will use pnpm instead od npm:
```bash
dotnet new vite -o my-vite-project --frontendFramework solid --useTypeScript --usePNPM
# alternative short form:
dotnet new vite -o my-vite-project -f solid -t -p
```


Example without https:
```bash
dotnet new vite -o my-vite-project --frontendFramework vanilla --useTypeScript --no-https
```

The templates supported by Vite (and, in extensions by this template) are:

- vanilla
Expand All @@ -43,6 +57,7 @@ The templates supported by Vite (and, in extensions by this template) are:
- preact
- lit
- svelte
- solid

All technologies can optionally be scaffolded with TypeScript support.

Expand Down
31 changes: 15 additions & 16 deletions src/Vite-CSharp.csproj.in
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<NoDefaultLaunchSettingsFile Condition="'$(ExcludeLaunchSettings)' == 'True'">True</NoDefaultLaunchSettingsFile>
<SpaRoot>ClientApp\</SpaRoot>
<SpaProxyServerUrl>https://localhost:5002</SpaProxyServerUrl>
<!-- <SpaProxyServerUrl Condition="'$(RequiresHttps)' == 'True'">https://localhost:5002</SpaProxyServerUrl>
<SpaProxyServerUrl Condition="'$(RequiresHttps)' != 'True'">http://localhost:5002</SpaProxyServerUrl> -->
<SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>
<SpaProxyServerUrl Condition="'$(RequiresHttps)' == 'True'">https://localhost:5002</SpaProxyServerUrl>
<SpaProxyServerUrl Condition="'$(RequiresHttps)' != 'True'">http://localhost:5002</SpaProxyServerUrl>
<!--#if (!UsePNPM) -->
<PackageManager>npm</PackageManager>
<!--#else -->
<PackageManager>pnpm</PackageManager>
<!--#endif -->
<SpaProxyLaunchCommand>$(PackageManager) start</SpaProxyLaunchCommand>
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.WebApplication1</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="6.0.0-preview.7.21378.6" />
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="6.0.5" />
</ItemGroup>

<ItemGroup>
Expand All @@ -25,25 +29,20 @@
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>

<ItemGroup>
<Content Include=".template.config\dotnetcli.host.json" />
<Content Include=".template.config\template.json" />
</ItemGroup>

<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Message Importance="high" Text="Restoring dependencies using '$(PackageManager)'. This may take several minutes..." />
<Exec WorkingDirectory="$(SpaRoot)" Command="$(PackageManager) install" />
</Target>

<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />
<Exec WorkingDirectory="$(SpaRoot)" Command="$(PackageManager) install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="$(PackageManager) run build" />

<!-- Include the newly-built files in the publish output -->
<ItemGroup>
Expand Down
7 changes: 3 additions & 4 deletions src/templates/Vite-CSharp/.files/lit-ts/aspnetcore-https.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This script sets up HTTPS for the application using the ASP.NET Core HTTPS certificate
const fs = require('fs');
const spawn = require('child_process').spawn;
const spawnSync = require('child_process').spawnSync;

const path = require('path');

Expand All @@ -21,16 +21,15 @@ const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
const keyFilePath = path.join(baseFolder, `${certificateName}.key`);

if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
spawn('dotnet', [
spawnSync('dotnet', [
'dev-certs',
'https',
'--export-path',
certFilePath,
'--format',
'Pem',
'--no-password',
], { stdio: 'inherit', })
.on('exit', (code) => process.exit(code));
], { stdio: 'inherit', });
}

module.exports = {
Expand Down
4 changes: 4 additions & 0 deletions src/templates/Vite-CSharp/.files/lit-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"types"
],
"scripts": {
//#if(RequiresHttps)
"prestart": "node ./aspnetcore-https.js",
//#endif
"start": "vite",
"dev": "vite",
"build": "tsc && vite build"
},
Expand Down
14 changes: 11 additions & 3 deletions src/templates/Vite-CSharp/.files/lit-ts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineConfig } from 'vite'
//#if (RequiresHttps)
import { readFileSync } from 'fs'
import { certFilePath, keyFilePath } from './aspnetcore-https'
//#endif

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -14,18 +16,24 @@ export default defineConfig({
}
},
server: {
//#if (RequiresHttps)
https: {
key: readFileSync(keyFilePath),
cert: readFileSync(certFilePath)
},
//#endif
port: 5002,
strictPort: true,
proxy: {
'/api': {
//#if (RequiresHttps)
target: 'https://localhost:5001/',
changeOrigin: true,
secure: true
//#else
target: 'http://localhost:5000/',
//#endif
secure: false,
changeOrigin: true
}
}
}
})
});
7 changes: 3 additions & 4 deletions src/templates/Vite-CSharp/.files/lit/aspnetcore-https.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This script sets up HTTPS for the application using the ASP.NET Core HTTPS certificate
const fs = require('fs');
const spawn = require('child_process').spawn;
const spawnSync = require('child_process').spawnSync;

const path = require('path');

Expand All @@ -21,16 +21,15 @@ const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
const keyFilePath = path.join(baseFolder, `${certificateName}.key`);

if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
spawn('dotnet', [
spawnSync('dotnet', [
'dev-certs',
'https',
'--export-path',
certFilePath,
'--format',
'Pem',
'--no-password',
], { stdio: 'inherit', })
.on('exit', (code) => process.exit(code));
], { stdio: 'inherit', });
}

module.exports = {
Expand Down
2 changes: 2 additions & 0 deletions src/templates/Vite-CSharp/.files/lit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"dist"
],
"scripts": {
//#if(RequiresHttps)
"prestart": "node ./aspnetcore-https.js",
//#endif
"start": "vite",
"dev": "vite",
"build": "vite build"
Expand Down
14 changes: 11 additions & 3 deletions src/templates/Vite-CSharp/.files/lit/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineConfig } from 'vite'
//#if (RequiresHttps)
import { readFileSync } from 'fs'
import { certFilePath, keyFilePath } from './aspnetcore-https'
//#endif

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -14,18 +16,24 @@ export default defineConfig({
}
},
server: {
//#if (RequiresHttps)
https: {
key: readFileSync(keyFilePath),
cert: readFileSync(certFilePath)
},
//#endif
port: 5002,
strictPort: true,
proxy: {
'/api': {
//#if (RequiresHttps)
target: 'https://localhost:5001/',
changeOrigin: true,
secure: true
//#else
target: 'http://localhost:5000/',
//#endif
secure: false,
changeOrigin: true
}
}
}
})
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This script sets up HTTPS for the application using the ASP.NET Core HTTPS certificate
const fs = require('fs');
const spawn = require('child_process').spawn;
const spawnSync = require('child_process').spawnSync;

const path = require('path');

Expand All @@ -21,16 +21,15 @@ const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
const keyFilePath = path.join(baseFolder, `${certificateName}.key`);

if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
spawn('dotnet', [
spawnSync('dotnet', [
'dev-certs',
'https',
'--export-path',
certFilePath,
'--format',
'Pem',
'--no-password',
], { stdio: 'inherit', })
.on('exit', (code) => process.exit(code));
], { stdio: 'inherit', });
}

module.exports = {
Expand Down
5 changes: 4 additions & 1 deletion src/templates/Vite-CSharp/.files/preact-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "preact-ts",
"version": "0.0.0",
"scripts": {
//#if(RequiresHttps)
"prestart": "node ./aspnetcore-https.js",
//#endif
"start": "vite",
"dev": "vite",
"build": "tsc && vite build",
Expand All @@ -12,7 +14,8 @@
"preact": "^10.5.13"
},
"devDependencies": {
"@preact/preset-vite": "^2.0.0",
"@preact/preset-vite": "^2.2.0",
"@babel/core": "^7.18.2",
"typescript": "^4.3.2",
"vite": "^2.6.4"
}
Expand Down
12 changes: 10 additions & 2 deletions src/templates/Vite-CSharp/.files/preact-ts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite'
//#if (RequiresHttps)
import { readFileSync } from 'fs'
import { certFilePath, keyFilePath } from './aspnetcore-https'
//#endif

// https://vitejs.dev/config/
export default defineConfig({
plugins: [preact()],
server: {
//#if (RequiresHttps)
https: {
key: readFileSync(keyFilePath),
cert: readFileSync(certFilePath)
},
//#endif
port: 5002,
strictPort: true,
proxy: {
'/api': {
//#if (RequiresHttps)
target: 'https://localhost:5001/',
changeOrigin: true,
secure: true
//#else
target: 'http://localhost:5000/',
//#endif
secure: false,
changeOrigin: true
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/templates/Vite-CSharp/.files/preact/aspnetcore-https.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This script sets up HTTPS for the application using the ASP.NET Core HTTPS certificate
const fs = require('fs');
const spawn = require('child_process').spawn;
const spawnSync = require('child_process').spawnSync;

const path = require('path');

Expand All @@ -21,16 +21,15 @@ const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
const keyFilePath = path.join(baseFolder, `${certificateName}.key`);

if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
spawn('dotnet', [
spawnSync('dotnet', [
'dev-certs',
'https',
'--export-path',
certFilePath,
'--format',
'Pem',
'--no-password',
], { stdio: 'inherit', })
.on('exit', (code) => process.exit(code));
], { stdio: 'inherit', });
}

module.exports = {
Expand Down
5 changes: 4 additions & 1 deletion src/templates/Vite-CSharp/.files/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "preact",
"version": "0.0.0",
"scripts": {
//#if(RequiresHttps)
"prestart": "node ./aspnetcore-https.js",
//#endif
"start": "vite",
"dev": "vite",
"build": "vite build",
Expand All @@ -12,7 +14,8 @@
"preact": "^10.5.13"
},
"devDependencies": {
"@preact/preset-vite": "^2.0.0",
"@preact/preset-vite": "^2.2.0",
"@babel/core": "^7.18.2",
"vite": "^2.6.4"
}
}
Loading