Webpack不会通过build.js生成bundle.js.

时间:2017-07-18 09:56:20

标签: webpack babeljs webpack-2 dev-to-production

我尝试使用bundle.js构建生产webpack.config.prod.js,但是当我运行npm run build命令时,它会执行prebuild脚本并停在build脚本上甚至没有试图运行它。因此,它根本不会创建bundle.js

我关注webpack v1的示例,我尝试迁移到v2并了解为什么build.js的运行不起作用。

这些是我的文件:

的package.json

{      
  "scripts": {        
    "lint": "esw webpack.config.* src buildScripts",        
    "test": "mocha --reporter progress buildScripts/testSetup.js \"src/**/*.test.js\"",        
    "clean-dist": "rimraf ./dist && mkdir dist",

// Executes prebuild script

    "prebuild": "npm-run-all clean-dist test lint",

// Stops on build script

    "build": "babel-node buildScripts/build.js",
    "postbuild": "babel-node buildScripts/distServer.js"
  },      
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-preset-latest": "^6.24.1",
    "babel-register": "^6.24.1",
    "chai": "^4.1.0",        
    "cheerio": "^1.0.0-rc.2",              
    "eslint": "^4.2.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-watch": "^3.1.2",
    "express": "^4.15.3",
    "jsdom": "^11.1.0",        
    "json-server": "^0.11.2",        
    "npm-run-all": "^4.0.2",        
    "rimraf": "^2.6.1",
    "webpack": "^3.3.0"
  }
}

webpack.config.prod.js

import path from 'path';
import webpack from 'webpack';

module.exports = {
    devtool: "source-map",
    entry: [
        path.resolve(__dirname, "src/index.js")
    ],
    target: "web",
    output: {
        path: path.resolve(__dirname, "dist"),
        publicPath: "/",
        filename: "bundle.js"
    },
    devServer: {
        noInfo: false
    },
    plugins: [
        new webpack.LoaderOptionsPlugin({
            debug: true
        }),
        //Minify JS
        new webpack.optimize.UglifyJsPlugin()
    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loaders: ["babel-loader"]
            }
        ]
    }
};

build.js

import webpack from 'webpack';
import webpackConfig from '../webpack.config.prod';    

process.env.NODE_ENV = 'production';

console.log('Generating minified bundle for production. This will take a moment...');

webpack(webpackConfig).run((err, stats) => {
    if (err) {            
        console.log(err);
        return 1;
    }        

    return 0;
});

0 个答案:

没有答案