Skip to content

Commit 8a234bb

Browse files
BuptStEveulivz
authored andcommitted
fix($core): cannot load assets when base is not '/' (close: #1238)(#1239)
1 parent 099d346 commit 8a234bb

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

packages/@vuepress/core/__tests__/plugin-api/PluginUtil.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { flattenPlugin } from '../../lib/plugin-api/util'
22

33
describe('flattenPlugin', () => {
4-
test('shoould hydrate plugin correctly', () => {
4+
test('should hydrate plugin correctly', () => {
55
const plugin = { name: 'a', shortcut: 'a', module: { enhanceAppFiles: 'file' }}
66
const hydratedPlugin = flattenPlugin(plugin, {}, {})
77
expect(hydratedPlugin.name).toBe('a')
@@ -10,15 +10,15 @@ describe('flattenPlugin', () => {
1010
expect(hydratedPlugin.enhanceAppFiles).toBe('file')
1111
})
1212

13-
test('shoould set \'enabled\' to false when \'pluginOptions\' is set to false.', () => {
13+
test('should set \'enabled\' to false when \'pluginOptions\' is set to false.', () => {
1414
const plugin = { name: 'a', shortcut: 'a', module: {}}
1515
const hydratedPlugin = flattenPlugin(plugin, false, {})
1616
expect(hydratedPlugin.name).toBe('a')
1717
expect(hydratedPlugin.shortcut).toBe('a')
1818
expect(hydratedPlugin.enabled).toBe(false)
1919
})
2020

21-
test('shoould flatten functional plugin correctly.', () => {
21+
test('should flatten functional plugin correctly.', () => {
2222
const config = jest.fn(() => ({ enhanceAppFiles: 'file' }))
2323
const plugin = { name: 'a', shortcut: 'a', module: config }
2424
const pluginOptions = {}
@@ -33,7 +33,7 @@ describe('flattenPlugin', () => {
3333
expect(Object.getPrototypeOf(config.mock.calls[0][1])).toBe(pluginContext)
3434
})
3535

36-
test('shoould flatten functional plugin correctly - options defaults to \'{}\'.', () => {
36+
test('should flatten functional plugin correctly - options defaults to \'{}\'.', () => {
3737
const config = jest.fn(() => ({ enhanceAppFiles: 'file' }))
3838
const plugin = { name: 'a', shortcut: 'a', module: config }
3939
const pluginOptions = undefined

packages/@vuepress/core/lib/dev.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function prepareServer (sourceDir, cliOptions = {}, context) {
1818
const chokidar = require('chokidar')
1919

2020
const prepare = require('./prepare/index')
21-
const { chalk, logger } = require('@vuepress/shared-utils')
21+
const { chalk, fs, logger } = require('@vuepress/shared-utils')
2222
const HeadPlugin = require('./webpack/HeadPlugin')
2323
const DevLogPlugin = require('./webpack/DevLogPlugin')
2424
const createClientConfig = require('./webpack/createClientConfig')
@@ -110,6 +110,8 @@ async function prepareServer (sourceDir, cliOptions = {}, context) {
110110
config = applyUserWebpackConfig(userConfig, config, false /* isServer */)
111111
}
112112

113+
const contentBase = path.resolve(sourceDir, '.vuepress/public')
114+
113115
const serverConfig = Object.assign({
114116
disableHostCheck: true,
115117
compress: true,
@@ -124,14 +126,19 @@ async function prepareServer (sourceDir, cliOptions = {}, context) {
124126
ignored: /node_modules/
125127
},
126128
historyApiFallback: {
129+
disableDotRule: true,
127130
rewrites: [
128-
{ from: /\.html$/, to: '/' }
131+
{ from: /./, to: path.posix.join(ctx.base, 'index.html') }
129132
]
130133
},
131134
overlay: false,
132135
host,
133-
contentBase: path.resolve(sourceDir, '.vuepress/public'),
136+
contentBase,
134137
before (app, server) {
138+
if (fs.existsSync(contentBase)) {
139+
app.use(ctx.base, require('express').static(contentBase))
140+
}
141+
135142
ctx.pluginAPI.options.beforeDevServer.syncApply(app, server)
136143
},
137144
after (app, server) {

packages/@vuepress/core/lib/webpack/createBaseConfig.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = function createBaseConfig ({
3939
.output
4040
.path(outDir)
4141
.filename(isProd ? 'assets/js/[name].[chunkhash:8].js' : 'assets/js/[name].js')
42-
.publicPath(isProd ? publicPath : '/')
42+
.publicPath(publicPath)
4343

4444
if (env.isDebug) {
4545
config.devtool('source-map')

0 commit comments

Comments
 (0)