简体   繁体   English

`npm run watch`不是在开发模式下编译,而是在生产中编译(-p标志)

[英]`npm run watch` not compiling in dev mode but does in production (-p flag)

I'm trying to run webpack --watch and it starts but it doesn't compile anything, it seems it stuck. 我正在尝试运行webpack --watch,它启动了,但是它没有编译任何东西,似乎卡住了。 The moment I run webpack --watch -p it works as intended but it's slow and I have to wait for every compilation at least 20 seconds. 当我运行webpack --watch -p时,它可以按预期工作,但是速度很慢,我必须等待每次编译至少20秒。

I tried getting more information using the --verbose / --info-verbosity verbose flags but I don't get ANY extra information. 我尝试使用--verbose / --info-verbosity verbose标志获取更多信息,但没有任何其他信息。 It seems to be stuck in early compilation. 它似乎停留在早期编译中。 I tried to get production and dev mode as close as I could together. 我试图使生产和开发模式尽可能地接近。

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(),
],
}];

I expect --watch to work without the -p flag. 我希望--watch能在没有-p标志的情况下工作。 It shows no error and is 'stuck' on: 它没有显示错误,并且“卡在”以下位置:

$ node_modules/.bin/webpack --watch             

webpack is watching the files…

The problem appeared to be deeply nested HTML, which didn't get Webpack stuck but it took an insane amount of time to compile the templates. 这个问题似乎是深度嵌套的HTML,它没有使Webpack陷入困境,但是编译模板花费了很多时间。 The culprit in this case was was VueLoader using Prettier 在这种情况下,罪魁祸首是使用Prettier的VueLoader

The problem is described here: 问题描述如下:

https://github.com/prettier/prettier/issues/4672 https://github.com/prettier/prettier/issues/4672

And the solution is to add: 解决方案是添加:

prettify: false

to

{
    test: /\.vue$/,
    loader: 'vue-loader',
    options: {
        prettify: false,
    }
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM