如何从工件中忽略位于dist文件夹中的文件?

时间:2019-04-10 11:49:45

标签: npm webpack bundle webpack-4

我正在将npm与webpack一起使用。我的项目中有index.js,并且包含此文件 * .js文件。

我的base.config文件是这样的:

const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const extractCSS = new MiniCssExtractPlugin({ filename: '[name].bundle-css.css', allChunks: true });
const extractLESS = new MiniCssExtractPlugin({ filename: '[name].bundle-less.css', allChunks: true });
const WebpackMd5Hash = require('webpack-md5-hash');
const babelOptions = {
    presets: [
        [
            '@babel/preset-env', {
                targets: {
                    browsers: [ 'ie >= 11' ]
                },
                useBuiltIns: 'entry'
            }
        ]
    ],
    plugins: ["angularjs-annotate", "transform-remove-strict-mode"]
};

module.exports = function (env) {
    return {
        context: path.resolve(__dirname + '/../src/MyProject/'),
        stats: {
            .....
        },
        entry: {
            zapp: [ 'babel-polyfill', './app/index.js' ] //index.js is input
        },
        output: {
            path: path.resolve(__dirname, '../src/MyProject/dist'),
            filename: '[name].bundle.js',
        },
        mode: 'none',
        module: {
            rules: [
                {
                    test: /\.js$/,
                    exclude: [
                        path.resolve(__dirname, '/src/MyProject/app/module/pi.ui')
                    ],
                    include: includePaths,
                    use: [{
                        loader: 'babel-loader?cacheDirectory=true',
                        options: babelOptions,
                    }],
                },
            ]
        }
    };
};

和我的prod.config像这样:

const path = require('path');
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const commonConfig = require('./webpack.base.config.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = function (env) {
    return webpackMerge(commonConfig(), {   
        devtool: 'source-map',
        devServer: {
            contentBase: path.resolve(__dirname, './'),  // New
            compress: true
        },
        mode: 'production',
        optimization: { 
            minimizer: [
                new UglifyJsPlugin({
                    test: /\.js(\?.*)?$/i,
                })
            ]
        },
        plugins: [
            new HtmlWebpackPlugin({
                hash: true,
                inject: false,
                filename: '../bundle.html',
                template: 'bundle.template.ejs'
            }),
            new webpack.LoaderOptionsPlugin({
                minimize: true,
                debug: false
            }),
            new webpack.DefinePlugin({
                'process.env': {
                    'NODE_ENV': JSON.stringify('production')
                }
            })
        ]
    });
};

我想缩小项目规模。因此,如果此文件已捆绑在一起,则不需要* .js文件。我的zapp.bundle.js已经包含所有js文件。我的意思是,我想忽略应用程序文件夹内的js文件。有什么办法吗? build artifact

0 个答案:

没有答案