Jordan Enev
Jordan Enev

Reputation: 18644

Webpack doesn't work, once it's ran via npm scripts

Once I run the following command in cli (cmd) everything is fine:

SET NODE_ENV=production webpack --config webpack.config.js

If I run it via npm scripts nothing happens - neither an oupput nor an error message. I tried to add --display-error-details, but it's the same.

Keep in mind that I'm on Windows.

Here is the webpack.config.js:

var fs = require('fs');
var path = require('path');
var webpack = require('webpack');

// Project configuration
var entries = {
    'js/application': ['./app/main']
};

var appPath = path.resolve(__dirname, 'app');
var buildPath = path.join(__dirname, 'build');
var modulesPath = path.resolve(__dirname, 'node_modules');

// We'll bundle some more files for dev purposes, hot-loader and stuff
if (process.env.NODE_ENV != 'production') {
    entries = {
        'js/application': [
            'webpack-hot-middleware/client?https://localhost:3000',
            './app/main',
            './app/styles/main.less'
        ]
    };
}

// Webpack configuration
module.exports =
{
    devtool: 'source-map',
    entry: entries,
    output: {
        path: buildPath,
        filename: '[name].js'
    },
    resolve: {
        root: [modulesPath, appPath],
        extensions: ['', '.js', '.jsx']
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin(),
        // needed for UIkit
        new webpack.ProvidePlugin({ // http://webpack.github.io/docs/shimming-modules.html
            $: "jquery",
            jQuery: "jquery",
            L:"leaflet"
        })
    ],
    module: {
        noParse: [],
        loaders: [
            {
                test: /\.jsx?$/,
                loader: 'babel',
                include: appPath
            }, {
                test: /\.json/,
                loader: "json-loader"
            }, {
                test: /\.less$/,
                loader: 'style!css!less'
            }, {
                test: /\.(eot|woff|woff2|ttf|svg|png|jpg)$/,
                loader: 'url-loader?limit=30000&name=[name]-[hash].[ext]'
            }
        ]
    }
};

Here are the package.json scripts:

 "scripts": {
    "build:webpack": "SET NODE_ENV=production webpack --config webpack.config.js"
  },

Upvotes: 0

Views: 486

Answers (2)

Scott
Scott

Reputation: 860

Your npm script is only a single command, what you're actually running is SET NODE_ENV={everything else}. To get your script working on Windows you need to change your one-line script to run two commands, e.g. SET NODE_ENV=production && webpack --config webpack.config.js.

A quote from the documentation copied from "How to run two commands in one line in Windows CMD?":

Using multiple commands and conditional processing symbols

& [...] command1 & command2
Use to separate multiple commands on one command line. Cmd.exe runs the first command, and then the second command.

&& [...] command1 && command2
Use to run the command following && only if the command preceding the symbol is successful. Cmd.exe runs the first command, and then runs the second command only if the first command completed successfully.

Upvotes: 2

axm__
axm__

Reputation: 2673

have you tried npm run build:webpack : https://docs.npmjs.com/misc/scripts

Upvotes: 0

Related Questions