Преглед изворни кода

【看板展示】【build目录内容全部由webpack打包生成】

zhuth пре 8 година
родитељ
комит
5e43de2cba

+ 2 - 1
kanban-client/.babelrc

@@ -6,5 +6,6 @@
     ],
     "plugins": [
         "transform-class-properties"
-    ]
+    ],
+    "compact": false
 }

+ 1 - 3
kanban-client/.gitignore

@@ -1,5 +1,3 @@
 node_modules/
-build/css/
-build/fetch/
-build/src/
+build/
 data/

+ 3 - 0
kanban-client/README.md

@@ -11,6 +11,9 @@
 ##### 20170914
 * 模块化打包调整
 * 组件自适应调整,并支持手动设置组件字体大小、table的行高
+##### 20170914
+* build目录内容全部由webpack打包生成(除了echarts.min.js需要手动引用,未找到自动引入的方案)
+* 继续优化打包文件,减小文件体积
 #### 运行
 * 本地运行
 ```

BIN
kanban-client/app/assets/images/favicon.ico


+ 1 - 1
kanban-client/app/component/Table.jsx

@@ -105,7 +105,7 @@ class TableModel extends React.Component {
 	splitData() {
 		this.cHeight = this._reactInternalInstance._hostParent._hostNode.offsetHeight;
 		this.cWidth = this._reactInternalInstance._hostParent._hostNode.offsetWidth;
-		this.rowCount = Math.round(this.cHeight/this.newProps.rowHeight);
+		this.rowCount = Math.round(this.cHeight/(this.newProps.rowHeight || 40));
 		this.rowHeight = this.cHeight/this.rowCount;
 		let a = this.newProps.data;
 		let result = [];

+ 1 - 1
kanban-client/app/constants/url.json

@@ -1,3 +1,3 @@
 {
-    "path": "http://10.10.100.191:8082/kanbanInstance/parseData/"
+    "path": "kanbanInstance/parseData/"
 }

+ 10 - 0
kanban-client/app/index.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head lang="en">
+  <meta charset="UTF-8">
+  <title>Board</title>
+</head>
+<body style="margin:0px">
+  <div id="root"></div>
+</body>
+</html>

+ 0 - 0
kanban-client/build/lib/echarts-for-react/echarts.min.js → kanban-client/app/lib/echarts.min.js


+ 0 - 14
kanban-client/build/index.html

@@ -1,14 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head lang="en">
-  <meta charset="UTF-8">
-  <link rel="stylesheet" href="./css/main.css" type="text/css" />
-  <title>Board</title>
-</head>
-<body style="margin:0px">
-  <div id="root"></div>
-  <script type="text/javascript" src="./lib/echarts-for-react/echarts.min.js"></script>
-  <script src="./commons.bundle.js"></script>
-  <script src="./src/main.bundle.js"></script>
-</body>
-</html>

+ 1 - 1
kanban-client/server.js

@@ -11,7 +11,7 @@ app.use(express.static(path.join(__dirname, 'build')))
 
 // send all requests to index.html so browserHistory works
 app.get('*', function (req, res) {
-  res.sendFile(path.join(__dirname, 'build', 'index.html'))
+  res.sendFile(path.join(__dirname, 'build', 'boardshow.html'))
 })
 
 var PORT = process.env.PORT || 8080

+ 24 - 9
kanban-client/webpack.config.js

@@ -1,6 +1,7 @@
 var path = require('path');
 var webpack = require('webpack');
 var ExtractTextPlugin = require('extract-text-webpack-plugin');
+var HtmlWebpackPlugin = require('html-webpack-plugin');
 
 module.exports = {
     entry: {
@@ -9,14 +10,16 @@ module.exports = {
         'src/title': './app/src/Title/Title.jsx',
         'src/table': './app/component/Table.jsx',
         'src/form': './app/src/Form/index.js',
-        'src/chart': './app/src/Charts/ECharts.js'
+        'src/chart': './app/src/Charts/ECharts.js',
+        vendor: ['react', 'react-dom']
     },
     externals: {
-        echarts: 'window.echarts'
+        echarts: 'echarts'
     },
     output: {
         path: path.resolve(__dirname, './build'),
-        filename: '[name].bundle.js'
+        filename: '[name].bundle.js',
+        chunkFilename: "[name].[chunkHash:8].js"
     },
     module: {
         loaders: [
@@ -49,6 +52,7 @@ module.exports = {
         ]
     },
     plugins: [
+        // webapck配置
         new webpack.LoaderOptionsPlugin({
             options: {
                 devServer: {
@@ -57,29 +61,40 @@ module.exports = {
                 }
             }
         }),
-        /**
-         * 代码压缩
-         */
+        // 代码压缩
         // new webpack.optimize.UglifyJsPlugin({
         //     compress: {
         //         warnings: false
         //     }
         // }),
+        // 生产环境
         new webpack.DefinePlugin({
             "process.env": {
                 NODE_ENV: JSON.stringify("production")
             }
         }),
+        // 样式分离打包
         new ExtractTextPlugin({
             filename: (getPath) => {
                 return getPath('css/[name].css').replace('src/', '').replace('css/js', 'css');
             },
             allChunks: true
         }),
+        // 公共模块打包
         new webpack.optimize.CommonsChunkPlugin({ 
-            names: 'commons',
-            filename: '[name].bundle.js',
-            minChunks: 4,
+            names: ['vendor', 'manifest']
         }),
+        // 生成入口html
+        new HtmlWebpackPlugin({                        //根据模板插入css/js等生成最终HTML
+            favicon:'./app/assets/images/favicon.ico', //favicon路径
+            filename:'./boardshow.html',    //生成的html存放路径,相对于 path
+            template:'./app/index.html',    //html模板路径
+            inject:true,    //允许插件修改哪些内容,包括head与body
+            hash:true,    //为静态资源生成hash值
+            minify:{    //压缩HTML文件
+                removeComments:true,    //移除HTML中的注释
+                collapseWhitespace:false    //删除空白符与换行符
+            }
+        })
     ]
 };