Skip to content

Commit

Permalink
fix: fix transform webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Jun 29, 2021
1 parent 9e925e5 commit d88e73f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export interface Resolve {
alias: Record<string, never>;
}

export type Entry = string | string[] | { [entryAlias: string]: string } | any;

export interface WebpackConfig extends Config {
mode?: string;
entry?: string | string[] | { [entryAlias: string]: string } | Function;
entry?: Entry;
output?: Output;
module?: Module;
resolve?: Resolve;
Expand Down
8 changes: 4 additions & 4 deletions src/transform/transformWebpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TransformContext } from './context'
import { initViteConfig, Transformer, transformImporters } from './transformer'
import path from 'path'
import { DEFAULT_VUE_VERSION } from '../constants/constants'
import { Entry } from '../config/webpack'

// convert webpack.config.js => vite.config.js
export class WebpackTransformer implements Transformer {
Expand All @@ -19,7 +20,6 @@ export class WebpackTransformer implements Transformer {
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']
Expand All @@ -34,7 +34,7 @@ export class WebpackTransformer implements Transformer {
if (webpackConfig.entry !== '' && webpackConfig.entry !== null) {
config.build.rollupOptions = {}
if (isObject(webpackConfig.entry)) {
webpackConfig.entry = suitableFormat(webpackConfig.entry)
config.build.rollupOptions.input = suitableFormat(webpackConfig.entry)
} else if (typeof webpackConfig.entry === 'function') {
config.build.rollupOptions.input = webpackConfig.entry()
} else {
Expand Down Expand Up @@ -79,8 +79,8 @@ function isObject (value : any) : boolean {
return Object.prototype.toString.call(value) === '[object Object]';
}

function suitableFormat (entry: Object) : { [entryAlias: string]: string } {
const res : { [entryAlias: string]: string } = {}
function suitableFormat (entry: Entry) : Entry {
const res : Entry = {}
Object.keys(entry).forEach(function (name) {
if (!Array.isArray(entry[name])) {
res[name] = entry[name]
Expand Down

0 comments on commit d88e73f

Please sign in to comment.