Webpack

De Banane Atomic
Aller à la navigationAller à la recherche

Liens

Configuration

webpack.config.js
const path = require('path');

module.exports = {
    context: path.join(__dirname, 'node_modules'),
    entry: {
        jquery: 'jquery/dist/jquery',
        bootstrap: [
            'bootstrap/dist/js/bootstrap',
            'bootstrap/dist/css/bootstrap.css'
        ]
    },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'wwwroot/bundles')
    },
    resolve: {
        extensions: ['.js'],
        modules: ["node_modules"]
    },
    module: {
        rules: [
            { // fichiers css
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            },
            { // fichiers font
                test: /\.(woff|woff2|eot|ttf|otf)$/,
                use: [
                    'file-loader'
                ]
            },
            { // fichiers images
                test: /\.(png|svg|jpg|gif)$/,
                use: [
                    'file-loader'
                ]
            }
        ]
    }
};
Bash.svg
yarn add style-loader css-loader file-loader --dev

NPM Scripts

package.json
"scripts": {
    "build": "webpack",  // webpack global
    "build": "node_modules\.bin\webpack"  // webpack local avec windows
}
Bash.svg
npm run build

Installation

Bash.svg
# locale
yarn add webpack webpack-cli --save

# exécuter
webpack