-
Notifications
You must be signed in to change notification settings - Fork 891
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
Hosting from a subdirectory #189
Comments
Hi david, i solved this problem with 2 things: first create a file vue.config.js in the project root, in same level of package.json put this content: then in route.js export default new Router({ |
@jcav2, this worked like a charm. Thank you for posting this solution; it's saved me countless hours of fiddling and debugging. |
not working on server subfolder.... |
Hi, I managed to make it work but in my case I'm trying to run 2 separate Vue applications under the same host. For example; Root Vue app: mysite.com Now the issue is routing in the second Vue app. If there's a sub route in the second Vue app, accessing those routes directly resolves to the root Vue app. For example; Only partial workaround I could come up with is to remove the history mode from the second vue app and then including hash in the url when directly accessing. For example; Any idea how to achieve this when hosting from a subdirectory when running multiple Vue apps? |
Instead of "baseUrl" try "publicPath" |
In this project template, what decides how to build application is webpack, and you configure it via To change how webpack builds it for production, go to the webpack.config.js part with So, to change public path, from where everything is hosted, you will need to change If you project is served from module.exports.output.publicPath = '/subdirectory/dist/' That would probably result in var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'build.js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
},{{#sass}}
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
],
},
{{/sass}}
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
{{#sass}}
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
],
'sass': [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
]
{{/sass}}
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
module.exports.output.publicPath = '/subdirectory/dist/'
} And another thing is with index.html. You see, the file is generated at the very beginning, when you create your project from this template. When you send it to the hosting place, you will have to change the path to That would probably result in <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ name }}</title>
</head>
<body>
<div id="app"></div>
<script src="dist/build.js"></script>
</body>
</html> |
Hi, can the base option in the vue-router be in an array? |
Thank you, this worked for me |
I'm trying to host a vue app on a subdirectory like https://my.site/folder/ but every time it tries looking for it in https;//my.site/dist/build.js.
Even when I changed the
index.html
to point todist/build
it finds the build file but nothing displaysI'm also using vue-router
I've checked online but all I keep seeing are to change
config/index.js
but this is for the webpack template.
The text was updated successfully, but these errors were encountered: