在开发模式下服务器上的npm启动后,Webpack项目未运行

时间:2016-09-08 13:30:20

标签: angularjs node.js deployment server webpack

您好我正在尝试将我的代码(Angular.js + webpack_node.js)从本地环境部署到开发服务器,并编写了以下代码。 BUt它似乎不起作用,npm run deploy给了我很多警告,并且在重新加载dns时页面是空的。

的package.json

{
  "name": "opgadminsuite",
  "version": "1.0.0",
  "description": "New adminsuite with client side independence",
  "main": "index.js",
  "scripts": {
    "local": "webpack-dev-server --content-base app",
    "postinstall": "npm run build",
    "server": "node server.js",
    "build": "webpack -p --config webpack.development.config.js",
    "clean": "rm app/bundle.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "autoprefixer-loader": "^3.2.0",
    "babel-core": "^6.11.4",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.9.0",
    "css-loader": "^0.23.1",
    "less": "^2.7.1",
    "less-loader": "^2.2.3",
    "style-loader": "^0.13.1",
    "webpack": "^1.13.1",
    "webpack-dev-server": "^1.14.1"
  },
  "dependencies": {
    "angular-clipboard": "^1.5.0",
    "angular-ui-router-styles": "0.0.6",
    "bootstrap": "^3.3.6",
    "bootstrap-webpack": "0.0.5",
    "jquery": "^3.1.0"
  }
}

Webpack.development.config.js

    var webpack = require('webpack');
var path = require("path");
var ExtractTextPlugin = require('extract-text-webpack-plugin');


module.exports = {
  context:path.resolve( __dirname + '/app'),
   entry:   "./index.js",
  output:{
    path:__dirname + "/app",
    filename:"bundle.js",
  //   publicPath: "http://localhost:9090/build/"
  },
  plugins: [
    new ExtractTextPlugin('style.css', { allChunks: true })
  ],
  module:{
    loaders:[
        {
        test: /\.js$/,
        exclude: '/node_modules/',
        loader: 'babel-loader',
        query: {
          presets: ["es2015"],  
        }

      },
             {test: /bootstrap\/js\//, loader: 'imports?jQuery=jquery' },
            {test: /\.less$/, loader: 'style-loader!css-loader!less-loader'},
            {test: /\.css$/, loader: 'style-loader!css-loader'},
            {test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }
    ]
  },
 devServer:{
    inline:true,
    port:8080
  },
   debug: true
}

Server.js

 var express = require('express');
var path = require('path');
var app = express();

app.use(express.static(__dirname));

var host = 'localhost';
// Serve application file depending on environment
app.get('/index.js', function(req, res) {
    if (process.env.PRODUCTION) {
        res.sendFile(__dirname + '/app/index.js');
    } else {
        res.redirect('//' + host + ':9090/app/index.js');
    }
});


var appVersions = [];
for (var i = 0; i < 18; i++) {
    var vee = '/' + i + '.index.js'
    appVersions.push(vee)
}
appVersions.forEach(function(name) {
    app.get(name, function(req, res) {
        res.sendFile(__dirname + '/app/' + name);
    });
});

// Serve aggregate stylesheet depending on environment
app.get('/style.css', function(req, res) {
    if (process.env.PRODUCTION) {
        res.sendFile(__dirname + '/app/style.css');
    } else {
        res.redirect('//' + host + ':9090/app/style.css');
    }
});

// Serve index page
app.get('*', function(req, res) {
    res.sendFile(__dirname + '/app/index.html');
});


if (!process.env.DEVELOPMENT) {
    var webpack = require('webpack');
    var WebpackDevServer = require('webpack-dev-server');
    var config = require('./webpack.development.config');

    new WebpackDevServer(webpack(config), {
        publicPath: config.output.publicPath,
        hot: true,
        noInfo: true,
        historyApiFallback: true
    }).listen(8080, host, function(err, result) {
        if (err) {
            console.log(err);
        }
    });
} else {
    console.log("DEVELOPMENT mode On")
}



var port = process.env.PORT || 8080;
var server = app.listen(port, function() {
    var host = server.address().address;
    var port = server.address().port;
    console.log('Essential Angular listening at http://%s:%s', host, port);
});

此处主机变量也是空的。任何人都可以告诉我,我在这里失踪了什么。可能是愚蠢的或可能是重复的,任何帮助都表示赞赏。

我已经研究并达到了这个状态,所以请不要帮助。 请建议,谢谢!

1 个答案:

答案 0 :(得分:0)

这是因为你没有在package.json中定义deploy。您应该使用与本地等人相同的脚本添加它。