npm - `npm run watch` 不在开发模式下编译,但在生产中编译(-p 标志)
问题描述
我正在尝试运行 webpack --watch 并且它启动但它没有编译任何东西,它似乎卡住了。我运行 webpack --watch -p 的那一刻,它按预期工作,但速度很慢,我必须等待每次编译至少 20 秒。
我尝试使用 --verbose / --info-verbosity 详细标志获取更多信息,但没有得到任何额外信息。它似乎停留在早期编译中。我试图让生产和开发模式尽可能接近。
var path = require('path')
var webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
module.exports = [{
name: 'viewenvision',
entry:[
'./src/main.js'
],
output: {
path: path.resolve(__dirname, './public/js/viewenvision/'),
publicPath: '/public/js/viewenvision/',
filename: 'build.raw.js'
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {}
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
},
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
},
]
},
externals: {
'vue': 'Vue',
'vuex': 'Vuex',
'vue-router': 'VueRouter',
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
},
devServer: {
historyApiFallback: true,
noInfo: true
},
performance: {
hints: false
},
watchOptions: {
poll: 100
},
devtool: '#inline-source-map',
plugins: [
new VueLoaderPlugin(),
],
}];
我希望 --watch 可以在没有 -p 标志的情况下工作。它没有显示错误并且“卡住”:
$ node_modules/.bin/webpack --watch
webpack is watching the files…
解决方案
问题似乎是深度嵌套的 HTML,它没有让 Webpack 卡住,但编译模板花费了疯狂的时间。在这种情况下,罪魁祸首是使用 Prettier 的 VueLoader
问题描述如下:
https://github.com/prettier/prettier/issues/4672
解决方案是添加:
prettify: false
至
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
prettify: false,
}
},
推荐阅读
- python - Python:使用 PyPDF2 和 io 对 PDF 中的页面进行编号
- javascript - React Highchart:同步图表和工具提示未突出显示点
- nixos - 如何覆盖默认的稳定 Nvidia 驱动程序
- c# - 在 C# 中带有索引的 ForEach
- php - 一次取消设置具有相同单词的数组项并将它们发送到另一个数组
- html - 如何使用 HTML 使图像的某些部分可点击?
- c++ - opencv cv::VideoCapture 无法理解的错误
- javascript - 堆栈中的中间元素
- c# - 在 32 位和 64 位系统中写入和读取注册表项
- angularjs - 如何在 AngularJS 中访问 ng-repeat 范围内的变量?