美文网首页
webpack配置

webpack配置

作者: FEDEA | 来源:发表于2019-03-18 13:21 被阅读0次

var path = require('path')
var webpack = require('webpack')
var MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = function getBaseConfig() {
    return Object.assign({
        mode: 'production',
        entry: {
            bundle: ['./src/root/index.js'],
        },
        optimization: {
            namedChunks: true
        },
        output: {
            filename: '[name].[contenthash].js',
            chunkFilename: 'chunks/[name].[contenthash].js'
        },
        plugins: [
            // new webpack.SourceMapDevToolPlugin({
            //     filename: 'sourcemaps/[file].map',
            //     publicPath: 'http://fake-sourcemap.com/dist/fallback/',
            // }),
            new webpack.DefinePlugin({
                'process.env.NODE_ENV': '"production"'
            }),
            new MiniCssExtractPlugin({
                // Options similar to the same options in webpackOptions.output
                // both options are optional
                filename: 'css/style.[contenthash].css',
                chunkFilename: 'css/[id].[contenthash].css',
            }),
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./buildVendor/vendor-manifest.json'),
            }),
            new webpack.HashedModuleIdsPlugin()
        ],
        bail: true,
        profile: true,
        module: {
            rules: [
                {
                    test: /\.js$/,
                    use: 'babel-loader?cacheDirectory',
                    exclude: /node_modules/
                },
                {
                    test: /\.base64\./,
                    use: 'base64-loader'
                },
                {
                    test: /\.(png|PNG|jpe?g|svg)$/,
                    use: [
                        {
                            loader: 'url-loader',
                            options: {
                                limit: 2048,
                                name: 'images/[name].[hash].[ext]'
                            }
                        }
                    ],
                    exclude: /\.base64\./
                },
                {
                    test: /\.(ttf|eot|woff(2)?)$/,
                    use: [
                        {
                            loader: 'file-loader',
                            options: {
                                limit: 2048,
                                name: 'fonts/[name].[hash].[ext]'
                            }
                        }
                    ],
                    exclude: /\.base64\./
                },
                {
                    test: /glyphicons-halflings-regular\.svg$/,
                    use: [
                        {
                            loader: 'file-loader',
                            options: {
                                limit: 2048,
                                name: 'fonts/[name].[hash].[ext]'
                            }
                        }
                    ],
                    exclude: /\.base64\./
                },
                {
                    test: /\.(gif)$/,
                    use: [
                        {
                            loader: 'file-loader',
                            options: {
                                name: 'images/[name].[hash].[ext]'
                            }
                        }
                    ],
                    exclude: /\.base64\./
                },
                {
                    test: /\.css$/,
                    use: [
                        'style-loader',
                        {
                            loader: 'css-loader',
                            options: {
                                modules: true,
                                importLoaders: true,
                                localIdentName: '[name]__[local]___[hash:base64:5]'
                            }
                        },
                        'postcss-loader'
                    ]
                },
                {
                    test: /\.less$/,
                    use: [
                        MiniCssExtractPlugin.loader,
                        'css-loader',
                        'postcss-loader',
                        {
                            loader: 'less-loader',
                            options: {
                                javascriptEnabled: true
                            }
                        }
                    ]
                }
            ]
        },
        resolve: {
            alias: {
                'deep-equal': path.resolve(__dirname, 'src/root/libs/deep-equal/index.js'),
                'omni-module': path.resolve(__dirname, 'src/root/libs/omni-module/index.js'),
                'key-ui': path.resolve(__dirname, 'node_modules/key-ui-vp2'),
                UICOMPONENTS: path.resolve(__dirname, './src/uicomponents'),
                ROOT: path.resolve(__dirname, './src/root'),
                MODULES: path.resolve(__dirname, './src/modules'),
                OMODULES: path.resolve(__dirname, './src/omodules'),
            }
        }
    })
}


相关文章

网友评论

      本文标题:webpack配置

      本文链接:https://www.haomeiwen.com/subject/qduvmqtx.html