Skip to content

Commit c10acbe

Browse files
committed
add mini app for test
1 parent 8304b2c commit c10acbe

32 files changed

+448
-5
lines changed

conf/webpack.config.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,8 @@ const config = {
173173
// plugins
174174
plugins: [
175175
new AngularWebpackPlugin({
176-
// tsConfigPath: path.resolve(__dirname, '../tsconfig.json'),
177-
// entryModule: path.resolve(__dirname, '../src/app/app.module#AppModule'),
178-
// skipCodeGeneration: true,
179-
// sourceMap: _DEV_ ? true : false
176+
tsconfig: path.resolve(__dirname, '../tsconfig.json'),
177+
jitMode: true,
180178
}),
181179
new MiniCssExtractPlugin({
182180
filename: "static/css/[name].[contenthash].css",

demos/app.component.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
2+
import { RouterOutlet } from '@angular/router'
3+
4+
@Component({
5+
selector: 'app-root',
6+
encapsulation: ViewEncapsulation.Emulated,
7+
imports: [
8+
RouterOutlet
9+
],
10+
template: `
11+
<h1>Angular Router Sample</h1>
12+
<h2>Hello, Angular</h2>
13+
<app-crisis-list></app-crisis-list>
14+
<app-heroes-list></app-heroes-list>
15+
<router-outlet></router-outlet>
16+
`,
17+
})
18+
export class AppComponent implements OnInit {
19+
20+
constructor () {
21+
}
22+
23+
public ngOnInit () {
24+
console.log('demo app entry')
25+
}
26+
}

demos/app.module.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { registerLocaleData } from '@angular/common';
2+
import zh from '@angular/common/locales/zh';
3+
import { LOCALE_ID, NgModule, OnInit } from '@angular/core';
4+
import { BrowserModule } from '@angular/platform-browser';
5+
import { CommonModule } from '@angular/common';
6+
import { AppComponent } from './app.component';
7+
import { AppRoutingModule } from './app.routes';
8+
import { CrisisModule } from './crisis-list/module'
9+
import { HeroesModule } from './heroes-list/module'
10+
11+
12+
registerLocaleData(zh);
13+
14+
@NgModule({
15+
// schemas: [],
16+
declarations: [
17+
AppComponent,
18+
],
19+
imports: [
20+
BrowserModule,
21+
CommonModule,
22+
CrisisModule,
23+
HeroesModule,
24+
AppRoutingModule,
25+
],
26+
exports: [
27+
],
28+
providers: [
29+
// provideRouter(routes),
30+
],
31+
bootstrap: [AppComponent],
32+
})
33+
export class AppModule {
34+
35+
}

demos/app.routes.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { NgModule } from '@angular/core';
2+
import { RouterModule, Routes } from '@angular/router';
3+
import { CrisisListComponent } from './crisis-list/component';
4+
import { HeroesListComponent } from './heroes-list/component';
5+
6+
export const routes: Routes = [
7+
{ path: 'crisis-list', component: CrisisListComponent },
8+
{ path: 'heroes-list', component: HeroesListComponent },
9+
{ path: '', redirectTo: '/crisis-list', pathMatch: 'full' },
10+
];
11+
12+
@NgModule({
13+
imports: [RouterModule.forChild(routes)],
14+
exports: [RouterModule],
15+
})
16+
export class AppRoutingModule { }

demos/app.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'zone.js';
2+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3+
import { AppModule } from './app.module';
4+
5+
platformBrowserDynamic().bootstrapModule(AppModule).catch((e) => console.error(e));

demos/crisis-list/component.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-crisis-list',
5+
encapsulation: ViewEncapsulation.Emulated,
6+
templateUrl: `./crisis-list.component.html`,
7+
})
8+
export class CrisisListComponent implements OnInit {
9+
10+
constructor () {
11+
}
12+
13+
public ngOnInit () {
14+
console.log('CrisisListComponent')
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h3>CRISIS CENTER</h3>
2+
<p>Get your crisis here</p>

demos/crisis-list/module.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule } from '@angular/core';
2+
// import { CommonModule } from '@angular/common';
3+
import { CrisisListComponent } from './component'
4+
5+
@NgModule({
6+
declarations: [CrisisListComponent],
7+
exports: [CrisisListComponent], // 导出组件
8+
// imports: [CommonModule],
9+
})
10+
export class CrisisModule { }

demos/heroes-list/component.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-heroes-list',
5+
encapsulation: ViewEncapsulation.Emulated,
6+
templateUrl: `./heroes-list.component.html`,
7+
})
8+
export class HeroesListComponent implements OnInit {
9+
10+
constructor () {
11+
}
12+
13+
public ngOnInit () {
14+
console.log('HeroesListComponent')
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h3>HEROES</h3>
2+
<p>Get your heroes here</p>

demos/heroes-list/module.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Component, NgModule, OnInit, ViewEncapsulation } from '@angular/core';
2+
import { HeroesListComponent } from './component'
3+
// import { CommonModule } from '@angular/common';
4+
5+
@NgModule({
6+
declarations: [HeroesListComponent],
7+
exports: [HeroesListComponent], // 导出组件
8+
// imports: [CommonModule]
9+
})
10+
export class HeroesModule { }

demos/index.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="x-ua-compatible" content="ie=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>CMS-管理后台</title>
8+
<base href="/">
9+
<!-- <link rel="manifest" href="/manifest.json"> -->
10+
</head>
11+
<body>
12+
<app-root>
13+
<div class="ant-spin ant-spin-spinning ant-spin-lg">
14+
<span class="ant-spin-dot"><i></i><i></i><i></i><i></i></span>
15+
<div class="ant-spin-text"></div>
16+
</div>
17+
</app-root>
18+
</body>
19+
</html>

demos/miniapp/about.component.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-about',
5+
template: `<h2>About Page</h2>`
6+
})
7+
export class AboutComponent {}

demos/miniapp/app-routing.module.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NgModule } from '@angular/core';
2+
import { RouterModule, Routes } from '@angular/router';
3+
import { HomeComponent } from './home.component';
4+
import { AboutComponent } from './about.component';
5+
6+
const routes: Routes = [
7+
{ path: '', component: HomeComponent }, // 根路径显示 HomeComponent
8+
{ path: 'about', component: AboutComponent } // /about 显示 AboutComponent
9+
];
10+
11+
@NgModule({
12+
imports: [RouterModule.forRoot(routes)],
13+
exports: [RouterModule]
14+
})
15+
export class AppRoutingModule {}

demos/miniapp/app.component.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-root',
5+
template: `
6+
<h1>Angular Routing Example</h1>
7+
<nav>
8+
<a routerLink="/">Home</a>
9+
<a routerLink="/about">About</a>
10+
</nav>
11+
<router-outlet></router-outlet> <!-- 用于渲染路由匹配的组件 -->
12+
`
13+
})
14+
export class AppComponent {}

demos/miniapp/app.module.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
import { AppComponent } from './app.component';
4+
import { HomeComponent } from './home.component';
5+
import { AboutComponent } from './about.component';
6+
import { AppRoutingModule } from './app-routing.module'; // 导入路由模块
7+
8+
@NgModule({
9+
declarations: [AppComponent, HomeComponent, AboutComponent],
10+
imports: [BrowserModule, AppRoutingModule], // 引入 BrowserModule 和 AppRoutingModule
11+
bootstrap: [AppComponent]
12+
})
13+
export class AppModule {}

demos/miniapp/home.component.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-home',
5+
template: `<h2>Home Page</h2>`
6+
})
7+
export class HomeComponent {}

demos/miniapp/index.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Angular Routing Example</title>
6+
</head>
7+
<body>
8+
<app-root></app-root>
9+
</body>
10+
</html>

demos/miniapp/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "@angular/compiler"
2+
import("./main")

demos/miniapp/main.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import 'zone.js';
2+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3+
import { AppModule } from './app.module';
4+
5+
platformBrowserDynamic().bootstrapModule(AppModule)
6+
.catch(err => console.error(err));

demos/tsconfig.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compileOnSave": false,
3+
"compilerOptions": {
4+
"outDir": "./dist",
5+
"sourceMap": true,
6+
"declaration": false,
7+
"module": "esnext",
8+
"moduleResolution": "node",
9+
"emitDecoratorMetadata": true,
10+
"experimentalDecorators": true,
11+
"target": "ESNext",
12+
"typeRoots": ["node_modules/@types"],
13+
"lib": ["es2017", "dom"],
14+
"baseUrl": "./demos",
15+
},
16+
"include": ["./**/*.ts"]
17+
}

demos/webpack.config.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { AngularWebpackPlugin } = require('@ngtools/webpack');
2+
const path = require('path');
3+
const HtmlWebpackPlugin = require("html-webpack-plugin")
4+
5+
module.exports = {
6+
devServer: {
7+
port: '9101',
8+
historyApiFallback: true, // 如果你使用的是 Angular 路由,推荐加上这个
9+
},
10+
mode: 'development', // 或者 'development'
11+
entry: './demos/app.ts', // 入口文件
12+
output: {
13+
path: path.resolve(__dirname, 'dist'),
14+
filename: 'bundle.js',
15+
publicPath: '/',
16+
assetModuleFilename: 'static/assets/[hash][ext][query]',
17+
},
18+
resolve: {
19+
extensions: ['.ts', '.js'], // 解析 .ts 和 .js 文件
20+
},
21+
module: {
22+
rules: [
23+
{
24+
test: /\.ts$/,
25+
use: [
26+
{
27+
loader: '@ngtools/webpack',
28+
},
29+
],
30+
},
31+
{
32+
test: /\.html$/,
33+
use: 'html-loader',
34+
},
35+
],
36+
},
37+
plugins: [
38+
new AngularWebpackPlugin({
39+
tsconfig: './demos/tsconfig.json',
40+
jitMode: true,
41+
}),
42+
new HtmlWebpackPlugin({
43+
title: 'CMS-FE DEV',
44+
filename: 'index.html',
45+
template: './demos/index.html',
46+
inject: 'body',
47+
templateParameters: false,
48+
})
49+
],
50+
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"start": "NODE_ENV=development webpack-dev-server --config conf/webpack.dev.conf.js",
1717
"dev": "yarn start",
1818
"clean": "rm -rf dist",
19+
"demo": "webpack-dev-server --config ./demos/webpack.config.js",
1920
"build": "NODE_ENV=production webpack --config conf/webpack.prod.conf.js",
2021
"test": "NODE_ENV=development yarn run dll && webpack --config conf/webpack.dev.conf.js",
2122
"lint": "NODE_ENV=development node_modules/.bin/tslint -c tslint.json -p tsconfig.json",

src/app/app.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export class AppComponent implements OnInit {
1111
}
1212

1313
public ngOnInit () {
14+
console.log('app entry')
1415
}
1516
}

src/app/app.routing.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AuthGuard } from '../utils/auth/auth-guard.service';
44
import { HomeComponent } from './home';
55
import { LoginComponent } from './login/login.component';
66

7-
const appRoutes: Routes = [
7+
export const appRoutes: Routes = [
88
{
99
path: 'login',
1010
component: LoginComponent,

src/app/demos/app.component.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-root',
5+
encapsulation: ViewEncapsulation.Emulated,
6+
template: `
7+
<h1>Angular Router Sample</h1>
8+
<app-crisis-list></app-crisis-list>
9+
<app-heroes-list></app-heroes-list>
10+
`,
11+
})
12+
export class AppComponent implements OnInit {
13+
14+
constructor () {
15+
}
16+
17+
public ngOnInit () {
18+
console.log('demo app entry')
19+
}
20+
}

0 commit comments

Comments
 (0)