Browse Source

chore: init

chenlei 2 years ago
parent
commit
c078f55db8
13 changed files with 74 additions and 220 deletions
  1. 1 1
      .gitignore
  2. 3 22
      README.md
  3. 12 0
      config.js
  4. 3 2
      package.json
  5. 11 0
      pnpm-lock.yaml
  6. 0 27
      src/App.vue
  7. BIN
      src/assets/logo.png
  8. 0 134
      src/components/HelloWorld.vue
  9. 1 11
      src/router/index.ts
  10. 0 5
      src/views/AboutView.vue
  11. 0 18
      src/views/HomeView.vue
  12. 10 0
      src/views/home/index.tsx
  13. 33 0
      vue.config.js

+ 1 - 1
.gitignore

@@ -1,6 +1,6 @@
 .DS_Store
 node_modules
-/dist
+/build
 
 
 # local env files

+ 3 - 22
README.md

@@ -1,24 +1,5 @@
-# 4dage-web
+## 多场景模式
 
-## Project setup
-```
-pnpm install
-```
+通过 `process.env.MUSEUM` 区分博物馆
 
-### Compiles and hot-reloads for development
-```
-pnpm run serve
-```
-
-### Compiles and minifies for production
-```
-pnpm run build
-```
-
-### Lints and fixes files
-```
-pnpm run lint
-```
-
-### Customize configuration
-See [Configuration Reference](https://cli.vuejs.org/config/).
+尽量使用 `.tsx` 后缀,因为 `.vue` 为自定义后缀,webpack暂不能友好支持 `.vue` 后缀,需要明确使用 `demo.vue`,导致无法区分场景

+ 12 - 0
config.js

@@ -0,0 +1,12 @@
+const ASSETS_DIR = 'resources/web/';
+
+module.exports = {
+  /**
+   * 静态资源部署位置
+   */
+  publicPath: process.env.MUSEUM ? `/${process.env.MUSEUM}/` : `/`,
+  /**
+   * 静态资源放置的子目录
+   */
+  assetsDir: ASSETS_DIR,
+}

+ 3 - 2
package.json

@@ -3,8 +3,8 @@
   "version": "0.1.0",
   "private": true,
   "scripts": {
-    "serve": "vue-cli-service serve",
-    "build": "vue-cli-service build",
+    "serve:hn": "cross-env MUSEUM=hn vue-cli-service serve",
+    "build:hn": "cross-env MUSEUM=hn vue-cli-service build",
     "lint": "vue-cli-service lint"
   },
   "dependencies": {
@@ -22,6 +22,7 @@
     "@vue/cli-plugin-typescript": "~5.0.0",
     "@vue/cli-service": "~5.0.0",
     "@vue/eslint-config-typescript": "^9.1.0",
+    "cross-env": "^7.0.3",
     "eslint": "^7.32.0",
     "eslint-config-prettier": "^8.3.0",
     "eslint-plugin-prettier": "^4.0.0",

+ 11 - 0
pnpm-lock.yaml

@@ -43,6 +43,9 @@ devDependencies:
   '@vue/eslint-config-typescript':
     specifier: ^9.1.0
     version: 9.1.0(@typescript-eslint/eslint-plugin@5.4.0)(@typescript-eslint/parser@5.4.0)(eslint-plugin-vue@8.0.3)(eslint@7.32.0)(typescript@4.5.5)
+  cross-env:
+    specifier: ^7.0.3
+    version: 7.0.3
   eslint:
     specifier: ^7.32.0
     version: 7.32.0
@@ -3399,6 +3402,14 @@ packages:
       yaml: 1.10.2
     dev: true
 
+  /cross-env@7.0.3:
+    resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==}
+    engines: {node: '>=10.14', npm: '>=6', yarn: '>=1'}
+    hasBin: true
+    dependencies:
+      cross-spawn: 7.0.3
+    dev: true
+
   /cross-spawn@5.1.0:
     resolution: {integrity: sha512-pTgQJ5KC0d2hcY8eyL1IzlBPYjTkyH72XRZPnLyKus2mBfNjQs3klqbJU2VILqZryAZUt9JOb3h/mWMy23/f5A==}
     dependencies:

+ 0 - 27
src/App.vue

@@ -1,30 +1,3 @@
 <template>
-  <nav>
-    <router-link to="/">Home</router-link> |
-    <router-link to="/about">About</router-link>
-  </nav>
   <router-view />
 </template>
-
-<style lang="scss">
-#app {
-  font-family: Avenir, Helvetica, Arial, sans-serif;
-  -webkit-font-smoothing: antialiased;
-  -moz-osx-font-smoothing: grayscale;
-  text-align: center;
-  color: #2c3e50;
-}
-
-nav {
-  padding: 30px;
-
-  a {
-    font-weight: bold;
-    color: #2c3e50;
-
-    &.router-link-exact-active {
-      color: #42b983;
-    }
-  }
-}
-</style>

BIN
src/assets/logo.png


+ 0 - 134
src/components/HelloWorld.vue

@@ -1,134 +0,0 @@
-<template>
-  <div class="hello">
-    <h1>{{ msg }}</h1>
-    <p>
-      For a guide and recipes on how to configure / customize this project,<br />
-      check out the
-      <a href="https://cli.vuejs.org" target="_blank" rel="noopener"
-        >vue-cli documentation</a
-      >.
-    </p>
-    <h3>Installed CLI Plugins</h3>
-    <ul>
-      <li>
-        <a
-          href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel"
-          target="_blank"
-          rel="noopener"
-          >babel</a
-        >
-      </li>
-      <li>
-        <a
-          href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router"
-          target="_blank"
-          rel="noopener"
-          >router</a
-        >
-      </li>
-      <li>
-        <a
-          href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint"
-          target="_blank"
-          rel="noopener"
-          >eslint</a
-        >
-      </li>
-      <li>
-        <a
-          href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript"
-          target="_blank"
-          rel="noopener"
-          >typescript</a
-        >
-      </li>
-    </ul>
-    <h3>Essential Links</h3>
-    <ul>
-      <li>
-        <a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a>
-      </li>
-      <li>
-        <a href="https://forum.vuejs.org" target="_blank" rel="noopener"
-          >Forum</a
-        >
-      </li>
-      <li>
-        <a href="https://chat.vuejs.org" target="_blank" rel="noopener"
-          >Community Chat</a
-        >
-      </li>
-      <li>
-        <a href="https://twitter.com/vuejs" target="_blank" rel="noopener"
-          >Twitter</a
-        >
-      </li>
-      <li>
-        <a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a>
-      </li>
-    </ul>
-    <h3>Ecosystem</h3>
-    <ul>
-      <li>
-        <a href="https://router.vuejs.org" target="_blank" rel="noopener"
-          >vue-router</a
-        >
-      </li>
-      <li>
-        <a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a>
-      </li>
-      <li>
-        <a
-          href="https://github.com/vuejs/vue-devtools#vue-devtools"
-          target="_blank"
-          rel="noopener"
-          >vue-devtools</a
-        >
-      </li>
-      <li>
-        <a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener"
-          >vue-loader</a
-        >
-      </li>
-      <li>
-        <a
-          href="https://github.com/vuejs/awesome-vue"
-          target="_blank"
-          rel="noopener"
-          >awesome-vue</a
-        >
-      </li>
-    </ul>
-  </div>
-</template>
-
-<script lang="ts">
-import { Options, Vue } from "vue-class-component";
-
-@Options({
-  props: {
-    msg: String,
-  },
-})
-export default class HelloWorld extends Vue {
-  msg!: string;
-}
-</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style scoped lang="scss">
-h3 {
-  margin: 40px 0 0;
-}
-ul {
-  list-style-type: none;
-  padding: 0;
-}
-li {
-  display: inline-block;
-  margin: 0 10px;
-}
-a {
-  color: #42b983;
-}
-</style>

+ 1 - 11
src/router/index.ts

@@ -1,20 +1,10 @@
 import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
-import HomeView from "../views/HomeView.vue";
 
 const routes: Array<RouteRecordRaw> = [
   {
     path: "/",
     name: "home",
-    component: HomeView,
-  },
-  {
-    path: "/about",
-    name: "about",
-    // route level code-splitting
-    // this generates a separate chunk (about.[hash].js) for this route
-    // which is lazy-loaded when the route is visited.
-    component: () =>
-      import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
+    component: () => import("@/views/home"),
   },
 ];
 

+ 0 - 5
src/views/AboutView.vue

@@ -1,5 +0,0 @@
-<template>
-  <div class="about">
-    <h1>This is an about page</h1>
-  </div>
-</template>

+ 0 - 18
src/views/HomeView.vue

@@ -1,18 +0,0 @@
-<template>
-  <div class="home">
-    <img alt="Vue logo" src="../assets/logo.png" />
-    <HelloWorld msg="Welcome to Your Vue.js + TypeScript App" />
-  </div>
-</template>
-
-<script lang="ts">
-import { Options, Vue } from "vue-class-component";
-import HelloWorld from "@/components/HelloWorld.vue"; // @ is an alias to /src
-
-@Options({
-  components: {
-    HelloWorld,
-  },
-})
-export default class HomeView extends Vue {}
-</script>

+ 10 - 0
src/views/home/index.tsx

@@ -0,0 +1,10 @@
+import { defineComponent } from "vue";
+
+export default defineComponent({
+  name: 'home',
+  render() {
+    return (
+      <div>home</div>
+    )
+  }
+})

+ 33 - 0
vue.config.js

@@ -1,5 +1,38 @@
 const { defineConfig } = require("@vue/cli-service");
+const path = require('path');
+const config = require('./config');
+
+const IS_PRODUCTION = process.env.NODE_ENV === 'production';
+// 当前博物馆
+const MUSEUM = process.env.MUSEUM;
+
+if (MUSEUM != null) {
+  console.log('当前博物馆:', MUSEUM);
+}
+
 module.exports = defineConfig({
   transpileDependencies: true,
   lintOnSave: false,
+  publicPath: IS_PRODUCTION ? config.publicPath : '/',
+  outputDir: (IS_PRODUCTION && !!MUSEUM) ? `build/${MUSEUM}` : 'build',
+  // 根据博物馆隔离
+  assetsDir: path.posix.join(config.assetsDir, MUSEUM || ''),
+
+  configureWebpack: {
+    resolve: {
+      symlinks: false,
+      alias: {
+        '@': path.join(__dirname, 'src'),
+      },
+    },
+  },
+
+  chainWebpack: (webpackConfig) => {
+    if (MUSEUM != null) {
+      const extensions = webpackConfig.resolve.extensions.values();
+      for (let i = extensions.length - 1; i >= 0; i--) {
+        webpackConfig.resolve.extensions.prepend(`.${MUSEUM}${extensions[i]}`);
+      }
+    }
+  }
 });