JavaScript

Knowledge Base

JavaScript / ECMAScript > Tools

Webpack

Installation mit

npm install --save-dev webpack

bzw. den DEV-Server mit

npm install --save-dev webpack-dev-server


webpack.config.dev.js - Beispiel:

var path = require("path");
var webpack = require("webpack");
 
module.exports =
{
    entry: {
        app: "./Source/app.jsx",
        vendor: [ "react", "react-dom" ]
    },
 
    output:
    {
        path: path.join(__dirname, "Build/"),
        filename: "JS/[name].bundle.js"
    },
 
    module:
    {
        rules:
        [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loader: "babel-loader",
                query:
                {
                    presets: [ "es2015", "react" ]
                }
            }
        ]
    },
 
    plugins:
    [
        // new webpack.DefinePlugin(
        //     { "process.env": { NODE_ENV: JSON.stringify("production") } }
        // ),
 
        new webpack.optimize.CommonsChunkPlugin(
            {
                name: "vendor",
                filename: "JS/vendor.bundle.js"
            }
        )
 
        // ,new webpack.optimize.UglifyJsPlugin(
        //     { compress: { warnings: false} }
        // )
    ],
 
    devServer:
    {
        publicPath: "/Build/"
    }
 
};