-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct entry script identification and webpack version detect (#…
- Loading branch information
Showing
13 changed files
with
13,179 additions
and
10,938 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@qiankunjs/webpack-plugin": patch | ||
--- | ||
|
||
fix: correct entry script identification and webpack version detection in Vue CLI 5 |
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,25 +1,40 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { describe, expect, it } from 'vitest'; | ||
import webpack4PackageJson from './webpack4/package.json'; | ||
import webpack5PackageJson from './webpack5/package.json'; | ||
import cheerio from 'cheerio'; | ||
|
||
describe('QiankunPlugin', () => { | ||
// webpack4 | ||
it('should work with webpack 4', async () => { | ||
// 获取包名 | ||
const packageName4 = webpack4PackageJson.name; | ||
|
||
// 检查产物 | ||
const htmlContent = fs.readFileSync(path.join(__dirname, 'tests/webpack4/dist/index.html'), 'utf-8'); | ||
expect(htmlContent).toContain('<script entry'); // 检查是否正确标记了 entry js | ||
const htmlContent4 = fs.readFileSync(path.join(__dirname, 'webpack4/dist/index.html'), 'utf-8'); | ||
const $4 = cheerio.load(htmlContent4); | ||
const hasEntryAttribute4 = $4('script[entry]').length > 0; | ||
expect(hasEntryAttribute4).toBe(true); // 检查是否正确标记了 entry js | ||
|
||
const jsChunkContent = fs.readFileSync(path.join(__dirname, 'tests/webpack4/dist/bundle.js'), 'utf-8'); | ||
expect(jsChunkContent).toContain('window.'); // 检查是否包含了 window. 关键字 | ||
const jsChunkContent4 = fs.readFileSync(path.join(__dirname, 'webpack4/dist/bundle.js'), 'utf-8'); | ||
const regex4 = new RegExp(`window(\\.\\${packageName4}|\\["${packageName4}"\\])`); | ||
expect(jsChunkContent4).toMatch(regex4); // 检查是否包含了 window.${packageName} 或 window["${packageName}"] | ||
}); | ||
|
||
// webpack5 | ||
it('should work with webpack 5', async () => { | ||
// 获取包名 | ||
const packageName5 = webpack5PackageJson.name; | ||
|
||
// 检查产物 | ||
const htmlContent = fs.readFileSync(path.join(__dirname, 'tests/webpack5/dist/index.html'), 'utf-8'); | ||
expect(htmlContent).toContain('<script entry'); // 检查是否正确标记了 entry js | ||
const htmlContent5 = fs.readFileSync(path.join(__dirname, 'webpack5/dist/index.html'), 'utf-8'); | ||
const $5 = cheerio.load(htmlContent5); | ||
const hasEntryAttribute5 = $5('script[entry]').length > 0; | ||
expect(hasEntryAttribute5).toBe(true); // 检查是否正确标记了 entry js | ||
|
||
const jsChunkContent = fs.readFileSync(path.join(__dirname, 'tests/webpack5/dist/bundle.js'), 'utf-8'); | ||
expect(jsChunkContent).toContain('window.'); // 检查是否包含了 window. 关键字 | ||
const jsChunkContent5 = fs.readFileSync(path.join(__dirname, 'webpack5/dist/bundle.js'), 'utf-8'); | ||
const regex5 = new RegExp(`window(\\.\\${packageName5}|\\["${packageName5}"\\])`); | ||
expect(jsChunkContent5).toMatch(regex5); // 检查是否包含了 window.${packageName} 或 window["${packageName}"] | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -7,5 +7,6 @@ | |
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script src="/js/app.12.js"></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
|
@@ -13,6 +13,6 @@ | |
"devDependencies": { | ||
"html-webpack-plugin": "^4.5.2", | ||
"webpack": "4", | ||
"webpack-cli": "3" | ||
"webpack-cli": "4" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,5 +7,6 @@ | |
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script entry src="a.js"></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
|
@@ -13,6 +13,6 @@ | |
"devDependencies": { | ||
"html-webpack-plugin": "^5.5.3", | ||
"webpack": "5", | ||
"webpack-cli": "4" | ||
"webpack-cli": "5" | ||
} | ||
} |
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
Oops, something went wrong.