Skip to content

Commit 24ba2f9

Browse files
author
longshihui
committed
feat(service): 兼容cli 3.3.0版本
fix #1
1 parent 9809f76 commit 24ba2f9

File tree

5 files changed

+252
-104
lines changed

5 files changed

+252
-104
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@vue/cli-plugin-babel": "^3.1.1",
4747
"@vue/cli-plugin-eslint": "^3.1.5",
4848
"@vue/cli-plugin-typescript": "^3.1.1",
49-
"@vue/cli-service": "^3.1.4",
49+
"@vue/cli-service": "^3.3.0",
5050
"@vue/eslint-config-airbnb": "^4.0.0",
5151
"@vue/eslint-config-typescript": "^3.1.1",
5252
"commitizen": "^2.10.1",

service/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable*/
2-
const path = require('path');
2+
const path = require('path').posix;
33
const fs = require('fs');
44
const HomepageDataCreator = require('../lib/HomepageDataCreator');
55
const OptionsDefaulter = require('../lib/OptionsDefaulter');
@@ -19,6 +19,8 @@ module.exports = (api, projectOptions) => {
1919
? path.resolve('./')
2020
: './node_modules/vue-cli-plugin-navigator';
2121
const packageJSON = readPackageConfig();
22+
// Compatible with cli 3.3.0
23+
const publicPath = projectOptions.publicPath || projectOptions.baseUrl;
2224

2325
let pluginOptions = utils.getPluginOptions(
2426
projectOptions,
@@ -64,10 +66,7 @@ module.exports = (api, projectOptions) => {
6466
rewrites: [
6567
{
6668
from: /./,
67-
to: require('path').posix.join(
68-
projectOptions.baseUrl,
69-
`${PLUGIN_NAME}.html`
70-
)
69+
to: path.join(publicPath, `${PLUGIN_NAME}.html`)
7170
}
7271
]
7372
});

tests/pages-project/vue.config.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/service.test.js

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ const MULTIPLE_PAGES_PROJECT_PATH = path.resolve('./tests/pages-project');
99
process.env.__VUE_CLI_PLUGIN_NAVIGATOR_TEST__ = true;
1010
process.env.VUE_CLI_TEST = true;
1111

12-
function createService(projectPath, mode) {
12+
function createService(projectPath, mode, projectOptions) {
1313
const service = new Service(projectPath, {
1414
plugins: [
1515
{
1616
id: 'inline:' + PLUGIN_NAME,
1717
apply: navigatorPlugin
1818
}
19-
]
19+
],
20+
inlineOptions: projectOptions
2021
});
2122
service.init(mode);
2223
return service;
@@ -31,7 +32,14 @@ describe('插件生效灰度测试', () => {
3132
test('多页模式下,插件生效', () => {
3233
const service = createService(
3334
MULTIPLE_PAGES_PROJECT_PATH,
34-
'development'
35+
'development',
36+
{
37+
assetsDir: './',
38+
pages: {
39+
page1: './src/pages/page1.js',
40+
page2: './src/pages/page2.js'
41+
}
42+
}
3543
);
3644
const webpackConfig = service.resolveWebpackConfig();
3745
expect(Object.keys(webpackConfig.entry).length).toBe(3);
@@ -40,9 +48,52 @@ describe('插件生效灰度测试', () => {
4048
test('多页模式下,插件只对development mode有效', () => {
4149
const service = createService(
4250
MULTIPLE_PAGES_PROJECT_PATH,
43-
'production'
51+
'production',
52+
{
53+
publicPath: '/static',
54+
assetsDir: './',
55+
pages: {
56+
page1: './src/pages/page1.js',
57+
page2: './src/pages/page2.js'
58+
}
59+
}
4460
);
4561
const webpackConfig = service.resolveWebpackConfig();
4662
expect(Object.keys(webpackConfig.entry).length).toBe(2);
4763
});
4864
});
65+
66+
describe('webpack dev server配置', () => {
67+
const projectOptions = {
68+
publicPath: '/static/',
69+
assetsDir: './',
70+
pages: {
71+
page1: './src/pages/page1.js',
72+
page2: './src/pages/page2.js'
73+
}
74+
};
75+
const service = createService(
76+
MULTIPLE_PAGES_PROJECT_PATH,
77+
'development',
78+
projectOptions
79+
);
80+
const webpackConfig = service.resolveWebpackConfig();
81+
test('index', () => {
82+
expect(webpackConfig.devServer.index).toBe(
83+
'vue-cli-plugin-navigator.html'
84+
);
85+
});
86+
test('openPage', () => {
87+
expect(webpackConfig.devServer.openPage).toBe(
88+
'vue-cli-plugin-navigator.html'
89+
);
90+
});
91+
test('historyApiFallback', () => {
92+
expect(webpackConfig.devServer.historyApiFallback.rewrites[0].to).toBe(
93+
path.resolve(
94+
projectOptions.publicPath,
95+
'vue-cli-plugin-navigator.html'
96+
)
97+
);
98+
});
99+
});

0 commit comments

Comments
 (0)