Skip to content

Commit

Permalink
fix($core): cannot load assets when base is not '/' (close: #1238)(#…
Browse files Browse the repository at this point in the history
  • Loading branch information
BuptStEve authored and ulivz committed Jan 29, 2019
1 parent 099d346 commit 8a234bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { flattenPlugin } from '../../lib/plugin-api/util'

describe('flattenPlugin', () => {
test('shoould hydrate plugin correctly', () => {
test('should hydrate plugin correctly', () => {
const plugin = { name: 'a', shortcut: 'a', module: { enhanceAppFiles: 'file' }}
const hydratedPlugin = flattenPlugin(plugin, {}, {})
expect(hydratedPlugin.name).toBe('a')
Expand All @@ -10,15 +10,15 @@ describe('flattenPlugin', () => {
expect(hydratedPlugin.enhanceAppFiles).toBe('file')
})

test('shoould set \'enabled\' to false when \'pluginOptions\' is set to false.', () => {
test('should set \'enabled\' to false when \'pluginOptions\' is set to false.', () => {
const plugin = { name: 'a', shortcut: 'a', module: {}}
const hydratedPlugin = flattenPlugin(plugin, false, {})
expect(hydratedPlugin.name).toBe('a')
expect(hydratedPlugin.shortcut).toBe('a')
expect(hydratedPlugin.enabled).toBe(false)
})

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

test('shoould flatten functional plugin correctly - options defaults to \'{}\'.', () => {
test('should flatten functional plugin correctly - options defaults to \'{}\'.', () => {
const config = jest.fn(() => ({ enhanceAppFiles: 'file' }))
const plugin = { name: 'a', shortcut: 'a', module: config }
const pluginOptions = undefined
Expand Down
13 changes: 10 additions & 3 deletions packages/@vuepress/core/lib/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function prepareServer (sourceDir, cliOptions = {}, context) {
const chokidar = require('chokidar')

const prepare = require('./prepare/index')
const { chalk, logger } = require('@vuepress/shared-utils')
const { chalk, fs, logger } = require('@vuepress/shared-utils')
const HeadPlugin = require('./webpack/HeadPlugin')
const DevLogPlugin = require('./webpack/DevLogPlugin')
const createClientConfig = require('./webpack/createClientConfig')
Expand Down Expand Up @@ -110,6 +110,8 @@ async function prepareServer (sourceDir, cliOptions = {}, context) {
config = applyUserWebpackConfig(userConfig, config, false /* isServer */)
}

const contentBase = path.resolve(sourceDir, '.vuepress/public')

const serverConfig = Object.assign({
disableHostCheck: true,
compress: true,
Expand All @@ -124,14 +126,19 @@ async function prepareServer (sourceDir, cliOptions = {}, context) {
ignored: /node_modules/
},
historyApiFallback: {
disableDotRule: true,
rewrites: [
{ from: /\.html$/, to: '/' }
{ from: /./, to: path.posix.join(ctx.base, 'index.html') }
]
},
overlay: false,
host,
contentBase: path.resolve(sourceDir, '.vuepress/public'),
contentBase,
before (app, server) {
if (fs.existsSync(contentBase)) {
app.use(ctx.base, require('express').static(contentBase))
}

ctx.pluginAPI.options.beforeDevServer.syncApply(app, server)
},
after (app, server) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@vuepress/core/lib/webpack/createBaseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function createBaseConfig ({
.output
.path(outDir)
.filename(isProd ? 'assets/js/[name].[chunkhash:8].js' : 'assets/js/[name].js')
.publicPath(isProd ? publicPath : '/')
.publicPath(publicPath)

if (env.isDebug) {
config.devtool('source-map')
Expand Down

0 comments on commit 8a234bb

Please sign in to comment.