写好了一个vue项目 如何用webpack打包?
我想知道大概的操作顺序
不涉及具体的细节
谢谢
webpack.config.js配好
运行webpack命令
输出了一大串错误信息:
求解~~~
加了url-loader以后错误不报了
webpack也打包完成了
但是从dist里点击index.html打开不了网页
是一个空白页
完整的webpack.config.js如下:
`
const path = require('path');
const root = path.resolve(__dirname);
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const rm = require('rimraf')
rm(path.join(root, 'dist'), err => {
if (err) throw err;
console.log('/dist目录删除成功')
});
module.exports = {
entry: path.resolve(root, 'src/main.js'),
output: {
path: path.resolve(root, 'dist'),
filename: 'bundle.js',
publicPath: './'
},
module: {
rules: [
{
test: /\.html$/i,
use: [
'html-loader',
'ejs-loader'
]
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.(png|jpe?g|gif)$/,
oneOf: [
{
resourceQuery: /base64/,
use: ['url-loader']
},
{
use: [{
loader: 'url-loader',
options: {
limit: 1,
name: 'img/[name].[hash:7].[ext]'
}
}]
}
]
},
{
test: /\.css$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: 'css/[name].[hash:7].[ext]'
}
}
}
]
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: 'css/[name].[hash:7].[ext]'
}
}
},
'sass-loader'
]
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 1,
name: 'fonts/[name].[ext]',
},
},
{
test: /\.(svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 1,
name: 'svg/[name].[ext]',
},
}
]
},
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template:path.resolve(root,"public/index.html")
})
]
};
`
谢谢大家的热心回答
问题原因找到了
因为router的mode不能设为history 而是需要hash
参考:
链接描述