-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parseWebpackConfig support multiple environments
- Loading branch information
Showing
14 changed files
with
676 additions
and
125 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,22 +1,22 @@ | ||
import { genePackageJson } from "../src/generate/genePackageJson"; | ||
import { genePackageJson } from '../src/generate/genePackageJson'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { genIndexHtml } from "../src/generate/geneIndexHtml"; | ||
import { readSync } from "../src/utils/file"; | ||
import { genIndexHtml } from '../src/generate/geneIndexHtml'; | ||
import { readSync } from '../src/utils/file'; | ||
import * as constants from '../src/constants/constants'; | ||
|
||
test('genePackageJson', () => { | ||
const packageJsonPath = path.resolve('./tests/testdata/generate/package.json'); | ||
genePackageJson(packageJsonPath); | ||
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf-8'); | ||
expect(JSON.parse(packageJsonContent).devDependencies['@vue/compiler-sfc']).toEqual(constants.VUE_COMPILER_SFC_VERSION); | ||
expect(JSON.parse(packageJsonContent).devDependencies['vite']).toEqual(constants.VITE_VERSION); | ||
expect(JSON.parse(packageJsonContent).devDependencies['@vitejs/plugin-vue']).toEqual(constants.VITE_PLUGIN_VUE_VERSION); | ||
const packageJsonPath = path.resolve('./tests/testdata/generate/package.json'); | ||
genePackageJson(packageJsonPath); | ||
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf-8'); | ||
expect(JSON.parse(packageJsonContent).devDependencies['@vue/compiler-sfc']).toEqual(constants.VUE_COMPILER_SFC_VERSION); | ||
expect(JSON.parse(packageJsonContent).devDependencies.vite).toEqual(constants.VITE_VERSION); | ||
expect(JSON.parse(packageJsonContent).devDependencies['@vitejs/plugin-vue']).toEqual(constants.VITE_PLUGIN_VUE_VERSION); | ||
}); | ||
|
||
test('genIndexHtml', () => { | ||
genIndexHtml('./tests/out'); | ||
const filePath = path.resolve('./tests/out/index.html'); | ||
const content = readSync(filePath); | ||
expect(content).toContain('src/main.js'); | ||
genIndexHtml('./tests/out'); | ||
const filePath = path.resolve('./tests/out/index.html'); | ||
const content = readSync(filePath); | ||
expect(content).toContain('src/main.js'); | ||
}) |
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,22 +1,32 @@ | ||
import { parseVueCliConfig, parseWebpackConfig } from "../src/config/parse"; | ||
import { WebpackConfig } from "../src/config/webpack"; | ||
import path from 'path'; | ||
import { VueCliConfig } from "../src/config/vuecli"; | ||
// import fs from 'fs'; | ||
import { parseVueCliConfig, parseWebpackConfig } from '../src/config/parse'; | ||
import { WebpackConfig } from '../src/config/webpack'; | ||
import { VueCliConfig } from '../src/config/vuecli'; | ||
|
||
test('parseWebpackConfig', async () => { | ||
let webpackConfig: WebpackConfig = {} ; | ||
const configPath = path.resolve('tests/testdata/webpack.config.js'); | ||
await parseWebpackConfig(configPath).then(res => { | ||
webpackConfig = res ; | ||
}); | ||
expect(webpackConfig.entry).toEqual('./main.js'); | ||
test('parse webpack.config.js', async () => { | ||
let webpackConfig: WebpackConfig = {}; | ||
const configPath = path.resolve('tests/testdata/webpack/webpack.config.js'); | ||
await parseWebpackConfig(configPath).then(res => { | ||
webpackConfig = res; | ||
}); | ||
expect(webpackConfig.entry).toEqual('./main.js'); | ||
}); | ||
|
||
test('parse build/webpack.dev.js', async () => { | ||
let webpackConfig: WebpackConfig = {}; | ||
const filePath = path.resolve('tests/testdata/webpack/build/webpack.dev.js'); | ||
await parseWebpackConfig(filePath).then(res => { | ||
webpackConfig = res | ||
}) | ||
expect(webpackConfig.entry['app']).toEqual('./src/app.js'); | ||
}) | ||
|
||
test('parseVueCliConfig', async () => { | ||
let vueCliConfig: VueCliConfig = {} | ||
const configPath = path.resolve('tests/testdata/vue.config.js'); | ||
await parseVueCliConfig(configPath).then(res => { | ||
vueCliConfig = res ; | ||
}); | ||
expect(vueCliConfig.baseUrl).toEqual('/src'); | ||
let vueCliConfig: VueCliConfig = {} | ||
const configPath = path.resolve('tests/testdata/vue.config.js'); | ||
await parseVueCliConfig(configPath).then(res => { | ||
vueCliConfig = res; | ||
}); | ||
expect(vueCliConfig.baseUrl).toEqual('/src'); | ||
}); |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.