UNPKG

@iamota/iamota-webpack

Version:

Helper tools for Webpack for iamota Framework (WordPress and Shopify)

86 lines (69 loc) 2.01 kB
// ---------------------------------------------------------------------------- // Webpack Base Config // ---------------------------------------------------------------------------- // // Webpack base configuration // // ---------------------------------------------------------------------------- // Webpack Tools const path = require('path'); // Webpack Plugins const {CleanWebpackPlugin} = require('clean-webpack-plugin'); /** * Initialize Config */ let config = {}; exports.init = function(config) { this.config = config; return this; }; /** * Base WebPack Config */ exports.baseConfig = ({ entry = path.resolve(this.config.projectPath, 'js/app.js'), outputFilename = 'js/[name].js', performance = { hints: 'error', maxEntrypointSize: this.config.isDev ? 5*1024*1024 : 3*1024*1024, // Source files (Dev: 5MB, Prod: 3MB) maxAssetSize: this.config.isDev ? 3*1024*1024 : 500*1024, // Output files (Dev: 3MB, Prod: 500KB) } } = {}) => ({ /** * Configuration */ context: this.config.projectPath, devtool: this.config.isDev ? 'inline-source-map' : 'source-map', mode: this.config.isDev ? 'development' : 'production', performance: performance, /** * Entry Point(s) to the WebPack Config */ entry: entry, /** * Output Path and Filename */ output: { path: this.config.outputPath, publicPath: this.config.publicPath, filename: outputFilename, }, /** * Optimization Settings */ optimization: { moduleIds: 'deterministic', }, /** * Extend Webpack with Plugins */ plugins: [ // Clean the output folder between builds new CleanWebpackPlugin({ verbose: true, cleanOnceBeforeBuildPatterns: [ this.config.outputPath ] }), ], });