-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
50 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export interface Config { | ||
rootDir?: string; | ||
type?: string; | ||
} | ||
|
||
export interface DevServer { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,49 @@ | ||
import { parseWebpackConfig } from '../config/parse'; | ||
import { RawValue, ViteConfig } from '../config/vite'; | ||
import { TransformContext } from './context'; | ||
import { initViteConfig, Transformer } from './transformer'; | ||
import path from 'path'; | ||
import { DEFAULT_VUE_VERSION } from '../constants/constants'; | ||
import { parseWebpackConfig } from '../config/parse' | ||
import { RawValue, ViteConfig } from '../config/vite' | ||
import { TransformContext } from './context' | ||
import { initViteConfig, Transformer } from './transformer' | ||
import path from 'path' | ||
import { DEFAULT_VUE_VERSION } from '../constants/constants' | ||
|
||
// convert webpack.config.js => vite.config.js | ||
export class WebpackTransformer implements Transformer { | ||
|
||
context : TransformContext = { | ||
vueVersion: DEFAULT_VUE_VERSION, | ||
config: initViteConfig(), | ||
importList: [], | ||
vueVersion: DEFAULT_VUE_VERSION, | ||
config: initViteConfig(), | ||
importList: [] | ||
} | ||
|
||
public async transform (rootDir: string): Promise<ViteConfig> { | ||
const webpackConfig = await parseWebpackConfig(path.resolve(rootDir, 'webpack.config.js')) | ||
const config = this.context.config | ||
|
||
// convert base config | ||
// TODO: convert entry | ||
// webpack may have multiple entry files, e.g. | ||
// 1. one entry, with one entry file : e.g. entry: './app/index.js' | ||
// 2. one entry, with multiple entry files: e.g. entry: ['./pc/index.js','./wap/index.js'] | ||
// 3. multiple entries e.g. entry: { | ||
// wap: './pc/index.js', | ||
// pc: './wap/index.js' | ||
// } | ||
config.mode = webpackConfig.mode | ||
|
||
const defaultAlias = [] | ||
|
||
public async transform(rootDir: string): Promise<ViteConfig> { | ||
const webpackConfig = await parseWebpackConfig(path.resolve(rootDir, 'webpack.config.js')) | ||
const config = this.context.config; | ||
|
||
// convert base config | ||
config.root = webpackConfig.entry | ||
config.mode = webpackConfig.mode | ||
const alias = { | ||
'@': `${rootDir}/src` | ||
} | ||
Object.keys(alias).forEach((key) => { | ||
const relativePath = path.relative(rootDir, alias[key]).replace(/\\/g, '/') | ||
defaultAlias.push({ | ||
find: key, | ||
replacement: new RawValue(`path.resolve(__dirname,'${relativePath}')`) | ||
}) | ||
}) | ||
|
||
const defaultAlias = []; | ||
|
||
const alias = { | ||
'@':`${rootDir}/src`, | ||
} | ||
Object.keys(alias).forEach((key) => { | ||
const relativePath = path.relative(rootDir,alias[key]).replace(/\\/g,'/'); | ||
defaultAlias.push({ | ||
find: key, | ||
replacement: new RawValue(`path.resolve(__dirname,'${relativePath}')`), | ||
}); | ||
}); | ||
config.resolve = {} | ||
config.resolve.alias = defaultAlias | ||
|
||
config.resolve = {}; | ||
config.resolve.alias = defaultAlias; | ||
|
||
return null | ||
return null | ||
} | ||
|
||
} |