【问题标题】:Webpack build step isn't generating build filesWebpack 构建步骤不生成构建文件
【发布时间】:2016-11-17 15:43:25
【问题描述】:

当我运行npm build 时,似乎什么也没发生。当我查找构建文件时,我什么也没看到。 npm start 工作正常。

包.json

{
  "name": "pro-react-webpack",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --progress",
    "build": "NODE_ENV=production webpack --config ./webpack.production.config.js --progress",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.10.4",
    "babel-loader": "^6.2.4",
    "babel-plugin-react-transform": "^2.0.2",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.11.1",
    "css-loader": "^0.23.1",
    "extract-text-webpack-plugin": "^1.0.1",
    "html-webpack-plugin": "^2.22.0",
    "json-loader": "^0.5.4",
    "postcss-loader": "^0.9.1",
    "precss": "^1.4.0",
    "react-transform-hmr": "^1.0.4",
    "style-loader": "^0.13.1",
    "webpack": "^1.13.1",
    "webpack-dev-server": "^1.14.1"
  },
  "dependencies": {
    "react": "^15.2.1",
    "react-dom": "^15.2.1"
  }
}

Webpack.production.config.js

var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    entry: __dirname + "/app/main.js",
    output: {
        path: __dirname + "/build",
        filename: "bundle.js"
    },

    module: {
        loaders: [
            {
                test: /\.json$/,
                loader: "json"
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel'
            },
            {
                test: /\.css$/,
                loader: ExtractTextPlugin.extract('style', 'css?modules!postcss')
            }
        ]
    },
    postcss: [
        require('autoprefixer')
    ],

    plugins: [
        new HtmlWebpackPlugin({
            template: __dirname + "/app/index.tmpl.html"
        }),
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.optimize.UglifyJsPlugin(),
        new ExtractTextPlugin("style.css")
    ]
}

我还有 .babelrc 文件和 webpack.config.js 文件,请告诉我这些文件是否也有用,谢谢。

【问题讨论】:

标签: javascript node.js npm webpack


【解决方案1】:

可能与 build 是一个内部命令有关。好像我过去也遇到过这种情况。看看这个Question

要运行自定义脚本,您可以使用npm run-script build 或仅使用npm run build。如NPM documentation中所述

【讨论】:

    猜你喜欢
    • 2018-10-20
    • 2018-09-27
    • 2019-02-18
    • 2012-01-03
    • 2013-07-15
    • 2018-10-10
    • 1970-01-01
    • 2020-06-08
    • 2017-03-07
    相关资源
    最近更新 更多