Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #1238, fix 404 when base config is not '/' #1239

Merged
merged 4 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason of changing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can reproduce it by this repo
https://github.com/BuptStEve/vuepress-bug


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