webpack install webpack config
npx webpack-cli init
webpack config example
npm install --save-dev webpack-dev-server
Source: medium.com
webpack/config/html
const path = require('path');
+const HtmlWebpackPlugin = require('html-webpack-plugin');

 module.exports = {
   entry: {
     index: './src/index.js',
     print: './src/print.js',
   },
+  plugins: [
+    new HtmlWebpackPlugin({
+      title: 'Output Management',
+    }),
+  ],
   output: {
     filename: '[name].bundle.js',
     path: path.resolve(__dirname, 'dist'),
   },
 };
webpack.config.js
// webpack.config.js/**
 * Webpack configuration.
 */const path = require( 'path' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const OptimizeCssAssetsPlugin = require( 'optimize-css-assets-webpack-plugin' );
const cssnano = require( 'cssnano' ); // https://cssnano.co/
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const UglifyJsPlugin = require( 'uglifyjs-webpack-plugin' );// JS Directory path.
const JS_DIR = path.resolve( __dirname, 'src/js' );
const IMG_DIR = path.resolve( __dirname, 'src/img' );
const BUILD_DIR = path.resolve( __dirname, 'build' );const entry = {
	main: JS_DIR + '/main.js',
	single: JS_DIR + '/single.js',
};const output = {
	path: BUILD_DIR,
	filename: 'js/[name].js'
};/**
 * Note: argv.mode will return 'development' or 'production'.
 */
const plugins = ( argv ) => [
	new CleanWebpackPlugin( {
		cleanStaleWebpackAssets: ( argv.mode === 'production' ) // Automatically remove all unused webpack assets on rebuild, when set to true in production. ( https://www.npmjs.com/package/clean-webpack-plugin#options-and-defaults-optional )
	} ),	new MiniCssExtractPlugin( {
		filename: 'css/[name].css'
	} ),
];const rules = [
	{
		test: /\.js$/,
		include: [ JS_DIR ],
		exclude: /node_modules/,
		use: 'babel-loader'
	},
	{
		test: /\.scss$/,
		exclude: /node_modules/,
		use: [
			MiniCssExtractPlugin.loader,
			'css-loader',
		]
	},
	{
		test: /\.(png|jpg|svg|jpeg|gif|ico)$/,
		use: {
			loader: 'file-loader',
			options: {
				name: '[path][name].[ext]',
				publicPath: 'production' === process.env.NODE_ENV ? '../' : '../../'
			}
		}
	},
];/**
 * Since you may have to disambiguate in your webpack.config.js between development and production builds,
 * you can export a function from your webpack configuration instead of exporting an object
 *
 * @param {string} env environment ( See the environment options CLI documentation for syntax examples. https://webpack.js.org/api/cli/#environment-options )
 * @param argv options map ( This describes the options passed to webpack, with keys such as output-filename and optimize-minimize )
 * @return {{output: *, devtool: string, entry: *, optimization: {minimizer: [*, *]}, plugins: *, module: {rules: *}, externals: {jquery: string}}}
 *
 * @see https://webpack.js.org/configuration/configuration-types/#exporting-a-function
 */
module.exports = ( env, argv ) => ({	entry: entry,	output: output,	/**
	 * A full SourceMap is emitted as a separate file ( e.g.  main.js.map )
	 * It adds a reference comment to the bundle so development tools know where to find it.
	 * set this to false if you don't need it
	 */
	devtool: 'source-map',	module: {
		rules: rules,
	},	optimization: {
		minimizer: [
			new OptimizeCssAssetsPlugin( {
				cssProcessor: cssnano
			} ),			new UglifyJsPlugin( {
				cache: false,
				parallel: true,
				sourceMap: false
			} )
		]
	},	plugins: plugins( argv ),	externals: {
		jquery: 'jQuery'
	}
});
webpack.config.js
const path = require('path');

// include the js minification plugin
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

// include the css extraction and minification plugins
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");

module.exports = {
  entry: ['./js/src/app.js', './css/src/app.scss'],
  output: {
    filename: './js/build/app.js',
    path: path.resolve(__dirname)
  },
  module: {
    rules: [
      // perform js babelization on all .js files
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ['babel-preset-env']
         }
        }
      },
      // compile all .scss files to plain old css
      {
        test: /\.(sass|scss)$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
      }
    ]
  },
  plugins: [
    // extract css into dedicated file
    new MiniCssExtractPlugin({
      filename: './css/build/main.min.css'
    })
  ],
  optimization: {
    minimizer: [
      // enable the js minification plugin
      new UglifyJSPlugin({
        cache: true,
        parallel: true
      }),
      // enable the css minification plugin
      new OptimizeCSSAssetsPlugin({})
    ]
  }
};

Javascript相关代码片段

angular can't bind to ngmodel

sandy liang

Toast Message always appears behind the modal

selenium and javascript

react native textinput should not autofill

form.getfieldvalue does not change antd

javascript zoom to bumber

javascript reduce exercises

array in js mdn

javascript built in priority queue

prevent parent click events from firing

what is intrinsic function in javascript

next js with pnpm

shopify emacs

dynamic scroll longitude antd table

tree vue js

eslint no-undef console

Count documents by field mongo

vertical column checkbox.group antd

dynamically adding class to anGULAR ELEMENT

random integer between 5 and 10 javascript

javascript refresh image src

url change tag javascript

change style using getelementsbyclassname

js uppercase türkçe

javascript sorting array using for loops

next js router not mounted

show image progress download in js

`NextRouter` was not mounted

Custom Dialog for GSheet

for each js on string

calculator in js

jsonserver

sweetalerts radio alert

how to add label to kubernetes node

react observer api

javascript metodlar

fixed height react quill editor

import js to postman

extract the domain name from a url javascript

react quill font colr doesn't change

Convert String to Date in JavaScript

signalr react

js regex srong password

password strength regex

import json into a var in typescript

Merge sort tree when two array is sorted

onOk button antd disable when loading

complex prop in react js

create react native app command

if regex javascript

react chart library npm

aos install-aos aos-install aos-setup-react

disable edit react-quill

string to array js

remove first character from string js

even numbers js

node-red date time

node-red settings local time

react boilerplate

sort linked list javascript

remove element rfrom js

settimeout example

is javascript oop language

set cookie for different domain javascript

how to slice an object in javascript

bulljs Named jobs

js on url change

how to enter a number in a square js

delete node_modules system wide

tasks json vscode c++ wsl

Use modbus in JS

calculator in javascript

add task to bulljs

free jqgrid

how to add variable to string javascript

How covert a number to a string

how to copy something to clipboard javascript

Install modbus-serial js

upload file in chunks function and call it