WebPack

Date: 2018-10-19

https://webpack.js.org/api/cli/

Start webpack project from command-line:

npx webpack init ./my-app --force --template=default

https://webpack.js.org/concepts/

Example webpack config

const path = require('path');
//const webpack = require('webpack');

module.exports = {
    entry: {
        player: './src/index.js'
    },
    output: {
        path: path.resolve(__dirname, '../../src/build'),
        filename: 'app-player.js'
    },
    module: {
        rules: [
            {
                enforce: 'pre',
                test: /\.js$/,
                exclude: /node_modules|shared\\lib/,
                loader: 'eslint-loader',
                options: {
                    useEslintrc: true
                }
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                options: {
                  presets: ['babel-preset-es2015'].map(require.resolve)
                }
            },
            {
                test: /\.css$/,
                use: ['css-loader']
                // options: {
                //     sourceMap: true
                // }
            }
        ]
    },
    stats: {
        colors: true
    },
    resolve: {
        alias: {
            wiring: path.resolve(__dirname, '../shared/wiring'),
            shared: path.resolve(__dirname, '../shared/'),
            bluebird: path.resolve(__dirname, '../shared/lib/bluebird.min'),
            'socket.io': path.resolve(__dirname, '../shared/lib/socket.io'),
            jquery: path.resolve(__dirname, '../shared/lib/jquery'),
            'jquery.transit': path.resolve(__dirname, '../shared/lib/jquery.transit'),
            sammy: path.resolve(__dirname, '../shared/lib/sammy'),
            tweenmax: path.resolve(__dirname, '../shared/lib/TweenMax.min')
        }
    },
    devtool: 'source-map'
};
{
  "name": "example-app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build-dev": "webpack --mode=development --source-map --info-verbosity verbose",
    "test": "webpack --mode=development --watch -w --config webpack-test.config.js",
    "run-dev": "webpack --mode=development --source-map --watch --info-verbosity verbose",
    "build": "webpack --mode=production"
  },
  "author": "",
  "license": "UNLICENCED",
  "devDependencies": {
    "babel-eslint": "^8.2.2",
    "babel-loader": "^7.1.4",
    "babel-preset-es2015": "^6.24.1",
    "css-loader": "^0.28.11",
    "eslint": "^4.19.1",
    "eslint-loader": "^2.0.0",
    "eslint-plugin-react": "^7.7.0",
    "mocha": "^5.0.5",
    "webpack": "^4.4.1",
    "webpack-cli": "^2.0.13",
    "webpack-node-externals": "^1.7.2",
    "webpack-shell-plugin": "^0.5.0"
  }
}
var path = require('path');
var webpack = require('webpack');

var nodeExternals = require('webpack-node-externals');
var WebpackShellPlugin = require('webpack-shell-plugin');

module.exports = {
    entry: {
        'player-tests': './src/tests.js',
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'app-[name].js'
    },
    stats: {
        colors: true
    },
    externals: [nodeExternals()],
    target: 'node',
    node: {
        fs: 'empty'
    },
    plugins: [new WebpackShellPlugin({
        onBuildExit: "mocha dist/app-player-tests.js"
    })],
    resolve: {
        alias: {
            jquery: path.resolve(__dirname, 'lib/jquery'),
            'jquery.transit': path.resolve(__dirname, 'lib/jquery.transit'),
            sammy: path.resolve(__dirname, 'lib/sammy')
        }
    },
    devtool: 'source-map'
};
7340cookie-checkWebPack