webpack仅编译具有最新更改的文件

时间:2019-06-12 06:44:04

标签: javascript webpack

我正在开发大型代码库;我有多个src文件要编译。当我运行watch或进行生产编译时,它将编译src中找到的所有文件。正是webpack应该做什么。

但是我只想编译最近已更改的文件,而不是所有文件。这可能吗?

这是我的webpack配置

const path = require("path");
const webpack = require("webpack");
const extractTextPlugin = require("extract-text-webpack-plugin");
const {VueLoaderPlugin} = require("vue-loader");

module.exports = {
    entry: {
        clients:
            "./src/clients/Resources/vue-js/clients.js",
        dashboard:
            "./src/dashboard/Resources/vue-js/dashboard.js",
        mapView:
            "./src/mapView/Resources/vue-js/mapView.js",
        admin:
            "./src/admin/Resources/vue-js/admin.js"
    },

    output: {
        path: path.join(__dirname, "./dist/"),
        publicPath: "/dist/",
        filename: "js/[name].js",
        chunkFilename: "js/[name].js"
    },
    optimization: {
        splitChunks: {
            cacheGroups: {
                vendors: {
                    name: "vendor",
                    filename: "js/vue_bundle.js",
                    automaticNameDelimiter: "_",
                    test: /[\\/]node_modules[\\/]/,
                    chunks: "all",
                    priority: 1,
                    minChunks: 2,
                    minSize: 0
                },
            }
        },
        occurrenceOrder: true,
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: "vue-loader"
            },
            {
                test: /\.js$/,
                loader: "babel-loader",
                exclude: /node_modules/,
                options: {
                    presets: ["env"]
                }
            },
            {
                test: /\.(png|woff|woff2|eot|ttf|svg)$/,
                loader: "url-loader?limit=100000"
            },
            {
                test: /\.css$/,
                use: extractTextPlugin.extract({
                    fallback: "style-loader",
                    use: "css-loader"
                })
            },
            {
                test: /\.scss$/,
                use: extractTextPlugin.extract({
                    // use: ['raw-loader', 'sass-loader']
                    use: "raw-loader!sass-loader"
                })
            },
            {
                test: /\.sass$/,
                use: extractTextPlugin.extract({
                    fallback: "style-loader",
                    use: "css-loader!sass-loader"
                })
            },
            {
                test: /\.jpe?g$|\.ico$|\.gif$|\.png$|\.svg$|\.woff$|\.ttf$|\.wav$|\.mp3$/,
                loader: "file-loader?name=[name].[ext]"
            },
            {
                test: /\.yaml$/,
                loader: "json-loader!yaml-loader"
            }
        ]
    },


    plugins: [
        new extractTextPlugin({
            filename: "css/[name].css",
            allChunks: true
        })
    ]
};

0 个答案:

没有答案