diff --git a/packages/@vuepress/core/__tests__/plugin-api/PluginUtil.spec.js b/packages/@vuepress/core/__tests__/plugin-api/PluginUtil.spec.js index 2bc618c2d3..211c2fbf6c 100644 --- a/packages/@vuepress/core/__tests__/plugin-api/PluginUtil.spec.js +++ b/packages/@vuepress/core/__tests__/plugin-api/PluginUtil.spec.js @@ -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') @@ -10,7 +10,7 @@ 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') @@ -18,7 +18,7 @@ describe('flattenPlugin', () => { 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 = {} @@ -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 diff --git a/packages/@vuepress/core/lib/dev.js b/packages/@vuepress/core/lib/dev.js index f8124f6968..8cca233f42 100644 --- a/packages/@vuepress/core/lib/dev.js +++ b/packages/@vuepress/core/lib/dev.js @@ -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') @@ -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, @@ -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) { diff --git a/packages/@vuepress/core/lib/webpack/createBaseConfig.js b/packages/@vuepress/core/lib/webpack/createBaseConfig.js index 71a158073a..c6b5a90cc1 100644 --- a/packages/@vuepress/core/lib/webpack/createBaseConfig.js +++ b/packages/@vuepress/core/lib/webpack/createBaseConfig.js @@ -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')