diff --git a/build/webpack.dev.config.js b/build/webpack.dev.config.js index 7d463c1c9..1a32a5496 100644 --- a/build/webpack.dev.config.js +++ b/build/webpack.dev.config.js @@ -3,6 +3,7 @@ const webpack = require('webpack') const basePath = path.resolve(__dirname, '../') module.exports = { + mode: 'development', entry: { main: ['babel-polyfill', `${path.resolve(basePath, 'site/main.js')}`], // 列出第三方库 @@ -75,8 +76,17 @@ module.exports = { children: false }, devtool: 'source-map', + optimization: { + splitChunks: { + cacheGroups: { + vendor: { + name: 'vendor' + } + } + } + }, plugins: [ - new webpack.HotModuleReplacementPlugin(), - new webpack.optimize.CommonsChunkPlugin({ name: 'vendor' }) + new webpack.HotModuleReplacementPlugin() + // new webpack.optimize.CommonsChunkPlugin({ name: 'vendor' }) ] } diff --git a/build/webpack.production.config.js b/build/webpack.production.config.js index ae14192ad..095f62c4d 100644 --- a/build/webpack.production.config.js +++ b/build/webpack.production.config.js @@ -3,10 +3,11 @@ const webpack = require('webpack') const HtmlWebpackPlugin = require('html-webpack-plugin') const CleanWebpackPlugin = require('clean-webpack-plugin') const ExtractTextPlugin = require('extract-text-webpack-plugin') - +const UglifyJsPlugin = require('uglifyjs-webpack-plugin') const basePath = path.resolve(__dirname, '../') module.exports = { + mode: process.env.NODE_ENV, entry: { main: ['babel-polyfill', `${path.resolve(basePath, 'site/main.js')}`], // 列出第三方库 @@ -97,6 +98,24 @@ module.exports = { chunks: false, children: false }, + optimization: { + minimize: true, + splitChunks: { + cacheGroups: { + vendor: { + name: 'vendor' + }, + runtime: { + name: 'runtime' + } + } + }, + minimizer: [ + new UglifyJsPlugin() + ], + usedExports: true, + sideEffects: true + }, plugins: [ new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) @@ -105,21 +124,21 @@ module.exports = { root: basePath }), new ExtractTextPlugin({ - filename: 'styles.[contenthash].css', + filename: 'styles.[hash].css', allChunks: true }), new HtmlWebpackPlugin({ title: 'HIUI Design', template: path.resolve(__dirname, '../site/index.template.html') }), - new webpack.optimize.UglifyJsPlugin({ - compress: { - warnings: false - } - }), - new webpack.optimize.CommonsChunkPlugin({ - name: ['vendor', 'runtime'] - }), + // new webpack.optimize.UglifyJsPlugin({ + // compress: { + // warnings: false + // } + // }), + // new webpack.optimize.CommonsChunkPlugin({ + // name: ['vendor', 'runtime'] + // }), new webpack.HashedModuleIdsPlugin() ] } diff --git a/components/upload/Upload.js b/components/upload/Upload.js index c56ef9833..275b94e59 100644 --- a/components/upload/Upload.js +++ b/components/upload/Upload.js @@ -1,6 +1,7 @@ import { Component } from 'react' import ReactDOM from 'react-dom' import PropTypes from 'prop-types' +import shallowEqual from 'shallowequal' import cloneDeep from 'lodash/cloneDeep' let fileId = 0 @@ -53,6 +54,14 @@ export default class Upload extends Component { // overEvent: false } + componentWillReceiveProps (nextProps) { + if (!shallowEqual(nextProps.defaultFileList, this.props.defaultFileList)) { + this.setState({ + fileList: this.prepareDefaultFileList(nextProps.defaultFileList) + }) + } + } + prepareDefaultFileList (fileList) { const _fileList = cloneDeep(fileList) diff --git a/libs/markdown/parse2demo.js b/libs/markdown/parse2demo.js index 84de0ab63..432d1237c 100644 --- a/libs/markdown/parse2demo.js +++ b/libs/markdown/parse2demo.js @@ -4,6 +4,7 @@ import PropTypes from 'prop-types' import marked from 'marked' import { transform } from 'babel-standalone' import Prism from 'prismjs' +import * as Components from '../../components' const LANG = { 'zh-CN': ['显示代码', '收起代码', '复制代码'], @@ -54,47 +55,34 @@ class Demo extends Component { } renderSource (value) { const { locale, theme } = this.props - import('../../components') - .then(Element => { - const args = ['context', 'React', 'ReactDOM'] - const argv = [this, React, ReactDOM] - - for (const key in Element) { - args.push(key) - argv.push(Element[key]) - } - - return { args, argv } - }) - .then(({ args, argv }) => { - const code = transform( - `class Demo extends React.Component { - ${value} - } + const args = ['context', 'React', 'ReactDOM'] + const argv = [this, React, ReactDOM] + const code = transform( + `class Demo extends React.Component { + ${value} + } + + ReactDOM.render( + + + + + + , document.getElementById('${this.playerId}')) + `, + { + presets: ['es2015', 'react'] + } + ).code + + for (const key in Components) { + args.push(key) + argv.push(Components[key]) + } + args.push(code) - ReactDOM.render( - - - - - - , document.getElementById('${this.playerId}')) - `, - { - presets: ['es2015', 'react'] - } - ).code - - args.push(code) - - var Fn = Function - new Fn(...args).apply(null, argv) - }) - .catch(err => { - if (process.env.NODE_ENV !== 'production') { - throw err - } - }) + var Fn = Function + new Fn(...args).apply(null, argv) } render () { diff --git a/package.json b/package.json index 52e60941b..acca3698b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hi-ui/hiui", - "version": "1.3.1", + "version": "1.3.2", "description": "HIUI for React", "scripts": { "test": "node_modules/.bin/standard && node_modules/.bin/stylelint --config .stylelintrc 'components/**/*.scss'", @@ -56,6 +56,7 @@ "redux": "^4.0.0", "redux-thunk": "^2.3.0", "shallowequal": "^1.0.2", + "uglifyjs-webpack-plugin": "^2.1.1", "universal-observer": "^1.0.1", "warning": "^3.0.0", "whatwg-fetch": "^2.0.4" @@ -77,7 +78,7 @@ "css-loader": "^0.28.11", "cssnano": "^4.0.5", "date-fns": "^1.29.0", - "extract-text-webpack-plugin": "^3.0.2", + "extract-text-webpack-plugin": "^4.0.0-beta.0", "file-loader": "^1.1.11", "gh-pages": "^2.0.1", "gulp": "^3.9.1", @@ -105,8 +106,9 @@ "stylelint-scss": "^3.4.0", "through2": "^2.0.3", "url-loader": "^1.0.1", - "webpack": "^3.12.0", - "webpack-dev-server": "^2.11.2" + "webpack": "^4.29.0", + "webpack-cli": "^3.2.1", + "webpack-dev-server": "^3.1.12" }, "standard": { "parser": "babel-eslint", diff --git a/site/index.html b/site/index.html index 7b4a572a3..734820628 100644 --- a/site/index.html +++ b/site/index.html @@ -9,7 +9,6 @@
-