Vuejs2 Vue:更改网页包应用程序生成路径以在网站的子目录中使用
我有一个vue应用程序,需要添加到现有网站的子目录中。示例:www.somesite.com/subdirectory/vue_application_此处 我的网页包文件如下所示: 我认为更改公共路径以匹配子目录会起作用,但在编辑它时似乎没有任何变化 我需要在我的webpack配置中更改什么,以便它在构建时不再在站点根目录中查找我的文件,而是在子目录中查找它们 请注意,这是一个非常简单的应用程序,因此我不使用vue路由器Vuejs2 Vue:更改网页包应用程序生成路径以在网站的子目录中使用,vuejs2,Vuejs2,我有一个vue应用程序,需要添加到现有网站的子目录中。示例:www.somesite.com/subdirectory/vue_application_此处 我的网页包文件如下所示: 我认为更改公共路径以匹配子目录会起作用,但在编辑它时似乎没有任何变化 我需要在我的webpack配置中更改什么,以便它在构建时不再在站点根目录中查找我的文件,而是在子目录中查找它们 请注意,这是一个非常简单的应用程序,因此我不使用vue路由器 var path = require('path') var webpa
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'
],
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// 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'
]
}
// 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
})
])
}
编辑:我似乎不用更改网页文件就能让它正常工作。我只需将索引中main.js文件的路径从/dist/build.js更改为dist/build.js,这样它就会显示在当前子目录中而不是站点根目录中 如果要从子目录生成,请更新条目文件路径,使其指向正确的文件?现在,您正在根目录的src文件夹中构建(假设此配置位于根目录中)
output.path
和output.publicPath
指定生成过程的输出,而不是输入。因此,如果我将publicPath:“/dist/”更改为publicPath:“dist/”,它应该在该目录中查找,而不是在站点根目录中查找,对吗?publicPath只确定要在浏览器中插入的url。它与构建过程无关。阅读文档:。您的输入文件包含构建树的信息,该树告诉webpack在哪里可以找到用于构建的所有其他文件。我似乎不用更改网页文件就可以让它工作了。我只需将索引中main.js文件的路径从/dist/build.js更改为dist/build.js,这样它就会显示在当前子目录中而不是站点根目录中。