diff --git a/tools/config/seed.config.ts b/tools/config/seed.config.ts index 379f9db604b48142a16edcb5a384b2eb4ce3ab7c..8d26f8dba0bbd521efc5c195f3d0169790d86dc0 100644 --- a/tools/config/seed.config.ts +++ b/tools/config/seed.config.ts @@ -1,4 +1,5 @@ import { join } from 'path'; +import * as slash from 'slash'; import { argv } from 'yargs'; import { Environments, InjectableDependency } from './seed.config.interfaces'; @@ -83,7 +84,7 @@ export class SeedConfig { * The base path of node modules. * @type {string} */ - NPM_BASE = join(this.APP_BASE, 'node_modules/'); + NPM_BASE = slash(join(this.APP_BASE, 'node_modules/')); /** * The flag for the hot-loader option of the application. @@ -451,25 +452,29 @@ export class SeedConfig { 'browser-sync': { middleware: [require('connect-history-api-fallback')({ index: `${this.APP_BASE}index.html`, -// rewrites: [ -// { -// from: /^\/node_modules\/.*$/, -// to: (context:any) => context.parsedUrl.pathname -// }, -// { -// from: new RegExp(`^${this.APP_BASE}${this.APP_SRC}$`), -// to: (context:any) => context.parsedUrl.pathname -// }, -// { -// from: /^\/assets\/.*$/, -// to: (context:any) => context.parsedUrl.pathname -// }, -// { -// from: /^\/css\/.*$/, -// to: (context:any) => context.parsedUrl.pathname -// } -// ], -// disableDotRule: true + rewrites: [ + { + from: new RegExp(`^${this.NPM_BASE}.*$`), + to: (context:any) => context.parsedUrl.pathname + }, + { + from: new RegExp(`^\/${this.BOOTSTRAP_DIR}\/.*$`), + to: (context:any) => context.parsedUrl.pathname + }, + { + from: new RegExp(`^${this.APP_BASE}${this.APP_SRC}\/.*$`), + to: (context:any) => context.parsedUrl.pathname + }, + { + from: new RegExp(`^${this.ASSETS_SRC.replace(this.APP_SRC, '')}\/.*$`), + to: (context:any) => context.parsedUrl.pathname + }, + { + from: new RegExp(`^${this.CSS_DEST.replace(this.APP_DEST, '')}\/.*$`), + to: (context:any) => `/${slash(join(this.APP_DEST, context.parsedUrl.pathname))}` + } + ], + disableDotRule: true })], port: this.PORT, startPath: this.APP_BASE, diff --git a/tools/tasks/seed/build.index.dev.ts b/tools/tasks/seed/build.index.dev.ts index 40eea0fc17dccd426009cf4304fa8fd9656d3744..9878fdb641637d05fb09311d7235589fa39e2944 100644 --- a/tools/tasks/seed/build.index.dev.ts +++ b/tools/tasks/seed/build.index.dev.ts @@ -62,6 +62,9 @@ function mapPath(dep: any) { */ function transformPath() { return function (filepath: string) { + if (filepath.startsWith(`/${Config.APP_DEST}`)) { + filepath = filepath.replace(`/${Config.APP_DEST}`, ''); + } arguments[0] = join(Config.APP_BASE, filepath) + `?${Date.now()}`; return slash(plugins.inject.transform.apply(plugins.inject.transform, arguments)); };