Skip to content

Commit

Permalink
支持工程热加载
Browse files Browse the repository at this point in the history
  • Loading branch information
baukh789 committed Mar 10, 2017
1 parent 4ceeb76 commit 868bc21
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build/demo/demo1.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<table grid-manager="cccc"></table>
<br/>
<hr/>
<button id="reset-gm" style="margin-left:100px;margin-bottom:10px;padding:5px 10px;display: none;">更换GridManage数据</button>
<button id="reset-gm" style="margin-left:100px;margin-bottom:10px;padding:5px 10px;display: none;">更换GridMana3333ge数据</button>
<script type="text/javascript">

// 创建方法
Expand Down
5 changes: 4 additions & 1 deletion build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"eslint-friendly-formatter": "^1.2.2",
"eslint-loader": "^1.1.0",
"eslint-plugin-standard": "^1.3.1",
"express": "^4.15.2",
"istanbul-instrumenter-loader": "^1.1.0",
"jTool": "^1.2.15",
"jasmine-ajax": "^3.2.0",
Expand All @@ -43,10 +44,12 @@
"uglifycss": "0.0.25",
"uglifyjs": "^2.4.10",
"watchify": "^3.7.0",
"webpack": "^1.13.0"
"webpack": "^1.13.0",
"webpack-dev-middleware": "^1.10.1"
},
"scripts": {
"report-coverage": "codecov",
"start": "node server",
"lint": "eslint src",
"test": "karma start",
"build": "npm run build:dev && npm run build:minified:js && npm run build:minified:css && npm run copy",
Expand Down
1 change: 1 addition & 0 deletions build/version/v2.3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
###新增
- 鼠标hove状态时,行列同时高亮
- React框架下渲染示例
- Angular框架下渲染示例

###变更
- 废弃参数: useDefaultStyle
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"eslint-friendly-formatter": "^1.2.2",
"eslint-loader": "^1.1.0",
"eslint-plugin-standard": "^1.3.1",
"express": "^4.15.2",
"istanbul-instrumenter-loader": "^1.1.0",
"jTool": "^1.2.15",
"jasmine-ajax": "^3.2.0",
Expand All @@ -43,10 +44,12 @@
"uglifycss": "0.0.25",
"uglifyjs": "^2.4.10",
"watchify": "^3.7.0",
"webpack": "^1.13.0"
"webpack": "^1.13.0",
"webpack-dev-middleware": "^1.10.1"
},
"scripts": {
"report-coverage": "codecov",
"start": "node server",
"lint": "eslint src",
"test": "karma start",
"build": "npm run build:dev && npm run build:minified:js && npm run build:minified:css && npm run copy",
Expand Down
78 changes: 30 additions & 48 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,32 @@
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs");
var express = require('express');
var app = express();
var path = require('path');
var url = require('url');
var webpack = require('webpack');
var config = require('./webpack-dev-config');
var compiler = webpack(config);

http.createServer(function (req, res) {
var pathname=__dirname + url.parse(req.url).pathname;
if (path.extname(pathname)=="") {
pathname+="/";
}
if (pathname.charAt(pathname.length-1)=="/"){
pathname+="index.html";
}
fs.exists(pathname,function(exists){
if(exists){
switch(path.extname(pathname)){
case ".html":
res.writeHead(200, {"Content-Type": "text/html"});
break;
case ".js":
res.writeHead(200, {"Content-Type": "text/javascript"});
break;
case ".css":
res.writeHead(200, {"Content-Type": "text/css"});
break;
case ".gif":
res.writeHead(200, {"Content-Type": "image/gif"});
break;
case ".jpg":
res.writeHead(200, {"Content-Type": "image/jpeg"});
break;
case ".png":
res.writeHead(200, {"Content-Type": "image/png"});
break;
default:
res.writeHead(200, {"Content-Type": "application/octet-stream"});
}
// 是否为开发模式; true: 使用src下的资源, false: 使用build下的资源
var isDev = true;
var target = 'build';
if(isDev){
target = 'src';
}
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: false,
stats: {
colors: true,
cached: false
},
publicPath: config.output.publicPath
}));

fs.readFile(pathname,function (err,data){
res.end(data);
});
} else {
res.writeHead(404, {"Content-Type": "text/html"});
res.end("<h1>404 Not Found</h1>");
}
});

}).listen(1987);

console.log("Server running at http://127.0.0.1:1987/");
// 配置资源路径
app.use(express.static(target));
app.listen(1987, function (err) {
if (err) {
console.log(err);
return;
}
console.log('started at http://localhost:1987');
});
57 changes: 57 additions & 0 deletions webpack-dev-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var webpack = require('webpack');
var path = require('path');
var TransferWebpackPlugin = require('transfer-webpack-plugin');
var buildPath = path.resolve(__dirname, "build");
var config = {
//入口文件配置
entry:path.resolve(__dirname, 'src/js/GridManager.js'),
resolve:{
extentions:["","js"]//当requrie的模块找不到时,添加这些后缀
},
//文件导出的配置
output:{
path: buildPath ,
filename: "js/GridManager.js",
publicPath: "/"
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
// mangle: false,
minimize: true,
warnings: false
}),
new TransferWebpackPlugin([
{from: __dirname + '/src/fonts', to: '/fonts'},
{from: __dirname + '/src/css', to: '/css'},
{from: __dirname + '/src/demo', to: '/demo'},
{from: __dirname + '/version', to: '/version'}
])
],
module: {
preLoaders: [
{
test: /\.(js|jsx)$/,
loader: 'eslint-loader',
include: [path.resolve(__dirname, "src/app")],
exclude: /(node_modules|bower_components)/
}
],
loaders: [
{
test: /\.js?$/,
loaders: ['babel?{"presets":["es2015"]}'],
exclude: /(node_modules|bower_components)/,
include: [path.join(__dirname, 'src')]
},
{
test:/\.css$/,
loader:'style!css',
exclude: /(node_modules|bower_components)/,
include: [path.join(__dirname, 'src')]
}
]
}
};

module.exports = config;

0 comments on commit 868bc21

Please sign in to comment.