【发布时间】:2018-06-14 06:10:39
【问题描述】:
我有一个 vue 项目,我已经使用 vue cli 安装了它。
我已经安装了 vue-router 并且所有路由在 npm run dev 模式下都可以正常工作。
网址是localhost:8000。之后,我运行 npm run build 命令,并导航到 url localhost/projet_name 这个正在部署的空白页面,并且没有路由工作。
我正在使用 Windows 系统并在 wampp 服务器上工作。
如果我想使用localhost/projet_name 运行项目,我应该怎么做?
这是我运行命令npm run build后的文件夹结构。
https://i.stack.imgur.com/HeoTG.png
webpack.config.js 文件是:
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: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
}
// 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
})
])
}
Packages.json 文件:
{
"name": "posthere",
"description": "A Vue.js project",
"version": "1.0.0",
"author": "Sandip",
"license": "MIT",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"vue": "^2.5.11",
"vue-resource": "^1.3.5",
"vue-router": "^3.0.1"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^5.0.5",
"css-loader": "^0.28.7",
"file-loader": "^1.1.4",
"vue-loader": "^13.0.5",
"vue-template-compiler": "^2.4.4",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
}
}
【问题讨论】:
-
我可以就这个问题寻求帮助吗?
-
能否请您发布 webpack.config.js 和 packages.json
-
构建配置中的 dist 目录路径似乎有问题
-
我尝试过一次 publicPath: 'dist/' (已修改),然后尝试再次运行命令“npm run build”,但没有给我结果。 @TalhaJunaid