webpack 4-webpack-dev-server未创建文件

时间:2018-09-20 12:43:38

标签: javascript webpack webpack-dev-server

我想用webpack-dev-server捆绑文件,一切正常,但是dev-server不会更改任何文件,保存后是编译文件但不创建任何文件且不更新它们。

此外,我看到它捆绑了来自node_modules的文件,并且我忽略了来自webpack.config.js

的排除规则

配置:

const path = require('path');

module.exports = {
    entry: './js/app.js',
    output: {
        path: path.resolve(__dirname, 'js'),
        filename: "out.js"
    },
    module: {
        rules: [
            {
                test: /\.js?$/,
                exclude: [
                    path.resolve(__dirname, './node_modules/')
                ],
                loader: 'babel-loader',
                options: {
                    presets: ['es2015']
                }
            },
            {
                test: /\.scss?$/,
                exclude: [
                    path.resolve(__dirname, 'node_modules')
                ],
                loader: 'style-loader!css-loader!sass-loader',

            },
            {
                test: /\.html?$/,
                use: {
                    loader: 'html-loader',
                    options: {
                        attrs: [':data-src']
                    }
                },
            },
            {
                test: /\.(png|jpg|gif)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {}
                    }
                ]
            }
        ]
    }
}

package.json

"scripts": {
    "start": "webpack-dev-server",
    "build": "webpack"
  },

我使用 npm start ,控制台向我显示了此信息:

enter image description here

1 个答案:

答案 0 :(得分:2)

当然,webpack-dev-server将更改保存在内存中并从那里进行存储,实际上,您不会在系统上找到更改的文件。如果您希望他们进行构建,请使用npm run build并将必要的选项传递给webpack,这将输出构建文件

在此处查看complete answer