123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // Imports
- const path = require('path');
- const HtmlWebpackPlugin = require('html-webpack-plugin')
- const MiniCssExtractPlugin = require("mini-css-extract-plugin");
- const BabelRegister = require("babel-register");
- const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
- const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
- const devMode = process.env.NODE_ENV !== 'production'
- // Webpack Configuration
- const config = {
- // Entry
- entry: './src/app.js',
- // Output
- output: {
- path: path.resolve(__dirname, './dist'),
- filename: '[name].[chunkhash].js'
- },
- optimization: {
- minimizer: [
- new UglifyJsPlugin({
- cache: true,
- parallel: true,
- sourceMap: true, // set to true if you want JS source maps
- uglifyOptions: {
- output: {
- comments: false
- }
- }
- }),
- new OptimizeCSSAssetsPlugin({})
- ],
- splitChunks: {
- cacheGroups: {
- commons: {
- chunks: "initial",
- minChunks: 2,
- maxInitialRequests: 5,
- minSize: 0
- },
- vendor: {
- test: /node_modules/,
- chunks: "initial",
- name: "vendor",
- priority: 10,
- enforce: true
- }
- }
- }
- },
- module: {
- rules : [
- {
- test: /\.js$/,
- exclude: /node_modules/,
- use: {
- loader: 'babel-loader',
- options: {
- presets: ['@babel/preset-env']
- }
- }
- },
- // CSS Files
- {
- test: /\.(sa|sc|c)ss$/,
- use: [
- devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
- 'css-loader',
- //'postcss-loader',
- 'sass-loader',
- ]
- },
- {
- test: /\.(png|jpg|gif|svg)$/i,
- use: [
- {
- loader: 'url-loader',
- options: {
- limit: 8192
- }
- }
- ]
- }
- ]
- },
- // Plugins
- plugins: [
- new HtmlWebpackPlugin({
- template: './src/template.html',
- filename: 'index.html',
- hash: true
- }),
- new MiniCssExtractPlugin({
- filename: devMode ? '[name].css' : '[name].[hash].css',
- chunkFilename: devMode ? '[id].css' : '[id].[hash].css',
- })
- ],
- // OPTIONAL
- // Reload On File Change
- watch: true,
- // Development Tools (Map Errors To Source File)
- devtool: 'source-map',
- };
- // Exports
- module.exports = config;
|