webpack.config.js
const webpack = require('webpack');
const path = require('path');
const { VueLoaderPlugin } = require('vue-loader')
module.exports = {
entry: path.resolve(__dirname, 'src', 'index.js'),
mode: 'development',
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist/',
filename: 'bundle.js'
},
devServer: {
contentBase: path.join(__dirname, "dist"),
historyApiFallback: true
},
module: {
rules: [
{
test: /\.css$/,
use: ['css-loader']
},
{
test: /\.vue$/,
use: 'vue-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
},
],
},
plugins: [
new VueLoaderPlugin()
],
resolve: {
alias: {
'vue': 'vue/dist/vue.esm.js'
}
}
}
目录结构
webpack.config.js
index.html
package.json
/src
index.js
App.vue
other files
/dist
<empty>
http://localhost:8080
当我在运行后打开webpack-serve --config webpack.config.js
以显示 index.html 文件时,该文件有一行,<script type="text/javascript" src="/dist/bundle.js"></script>
我得到 404。
--hot
使用标志运行它也是如此。
当我使用该--dev
标志时,我收到此错误并且服务器无法启动。
TypeError: Cannot create property 'publicPath' on boolean 'true'
at fn (/mnt/c/workspace/docker/budget/node_modules/koa-webpack/index.js:81:28)
at Object.webpack (/mnt/c/workspace/docker/budget/node_modules/webpack-serve/lib/server.js:32:25)
at Promise.all.then (/mnt/c/workspace/docker/budget/node_modules/webpack-serve/lib/server.js:127:24)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Error: An error was thrown while initializing koa-webpack
TypeError: Cannot create property 'publicPath' on boolean 'true'
at Object.webpack (/mnt/c/workspace/docker/budget/node_modules/webpack-serve/lib/server.js:43:15)
at Promise.all.then (/mnt/c/workspace/docker/budget/node_modules/webpack-serve/lib/server.js:127:24)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
我正在使用webpack-serve 0.3.1
编辑 1
这就是它变得奇怪的地方。尽管上面有所有路径和诸如此类的选项,但这个http://localhost:8080/bundle.js
或/bundle.js
解决了捆绑包和所有功能,如热重载,就像一个魅力。