diff --git a/package.json b/package.json index 15586ae860..6bc3fb8aa3 100644 --- a/package.json +++ b/package.json @@ -140,10 +140,10 @@ "scripts": { "babel": "babel components index.js --out-dir lib", "clean-build": "rm -rf _site _data && ./scripts/build-website.js", - "dora": "dora -p 8001 --plugins \"webpack?disableNpmInstall&config=webpack.website.config.js,hmr?config=webpack.website.config.js\"", + "dora": "ANTD=WEBSITE dora -p 8001 --plugins webpack?disableNpmInstall,hmr", "start": "npm run clean-build && npm run dora", "copy-html": "cp ./index.html ./_site/index.html && mkdir ./_site/_site && mv ./_site/demo-* ./_site/_site", - "site": "npm run clean-build && atool-build -o ./_site --config webpack.website.config.js && npm run copy-html", + "site": "npm run clean-build && ANTD=WEBSITE atool-build -o ./_site && npm run copy-html && ANTD=PRODUCTION atool-build && cp -R dist _site/dist", "deploy": "rm -rf node_modules && node scripts/install.js && npm run just-deploy", "just-deploy": "npm run site && node scripts/deploy.js", "lint": "npm run srclint && npm run mdlint && npm run lesshint", diff --git a/webpack.antd.config.js b/webpack.antd.config.js deleted file mode 100644 index cac3a29c5a..0000000000 --- a/webpack.antd.config.js +++ /dev/null @@ -1,22 +0,0 @@ -module.exports = function(webpackConfig) { - webpackConfig.entry = { - 'antd': ['./style/index.less', './index.js'] - }; - webpackConfig.externals = { - 'react': { - root: 'React', - commonjs2: 'react', - commonjs: 'react', - amd: 'react' - }, - 'react-dom': { - root: 'ReactDOM', - commonjs2: 'react-dom', - commonjs: 'react-dom', - amd: 'react-dom' - } - }; - webpackConfig.output.library = 'antd'; - webpackConfig.output.libraryTarget = 'umd'; - return webpackConfig; -}; diff --git a/webpack.config.js b/webpack.config.js index c1d081a166..270fbd073e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,71 +1,36 @@ -var webpack = require('webpack'); -var ExtractTextPlugin = require("extract-text-webpack-plugin"); -var path = require('path'); -var pkg = require('./package'); -var autoprefixer = require('autoprefixer'); +module.exports = function(webpackConfig) { + if (process.env.ANTD === 'WEBSITE') { + webpackConfig.entry = { + index: './site/entry/index.jsx', + }; + webpackConfig.resolve.root = process.cwd(); + webpackConfig.resolve.alias = { + antd: 'index', + BrowserDemo: 'site/component/BrowserDemo', + }; + } -var entry = {}; -entry['demo'] = ['./scripts/demo.js', 'webpack-hot-middleware/client']; - -module.exports = { - entry: entry, - - cache: true, - - resolve: { - extensions: ['', '.js', '.jsx'], - unsafeCache: true - }, - - noParse: /_site|node_modules/, - - output: { - path: path.join(process.cwd(), 'dist'), - publicPath: '/dist/', - filename: '[name].js' - }, - - module: { - loaders: [{ - test: /\.jsx?$/, - exclude: /node_modules/, - loader: 'es3ify' - }, { - test: /\.jsx?$/, - exclude: /node_modules/, - loader: 'babel', - query: { - cacheDirectory: true, - presets: ['es2015', 'react', 'stage-0', 'react-hmre'], - plugins: ['add-module-exports'] + if (process.env.ANTD === 'PRODUCTION') { + webpackConfig.entry = { + 'antd': ['./style/index.less', './index.js'] + }; + webpackConfig.externals = { + 'react': { + root: 'React', + commonjs2: 'react', + commonjs: 'react', + amd: 'react' + }, + 'react-dom': { + root: 'ReactDOM', + commonjs2: 'react-dom', + commonjs: 'react-dom', + amd: 'react-dom' } - }, { - test: /\.json$/, - exclude: /node_modules/, - loader: 'json-loader' - }, { - test: /\.less$/, - exclude: /node_modules/, - loader: ExtractTextPlugin.extract( - 'css?sourceMap&-minimize!' + 'postcss-loader!' + 'less?sourceMap' - ) - }, { - test: /\.css$/, - exclude: /node_modules/, - loader: ExtractTextPlugin.extract( - 'css?sourceMap&-minimize!' + 'postcss-loader' - ) - }] - }, + }; + webpackConfig.output.library = 'antd'; + webpackConfig.output.libraryTarget = 'umd'; + } - postcss: [autoprefixer], - - plugins: [ - new ExtractTextPlugin('[name].css'), - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.HotModuleReplacementPlugin(), - new webpack.NoErrorsPlugin() - ], - - devtool: 'cheap-module-source-map' + return webpackConfig; }; diff --git a/webpack.deploy.config.js b/webpack.deploy.config.js deleted file mode 100644 index 5f281b448c..0000000000 --- a/webpack.deploy.config.js +++ /dev/null @@ -1,25 +0,0 @@ -var webpack = require('webpack'); -var config = require('./webpack.config'); - -delete config.devtool; -config.entry.demo = [config.entry.demo[0]]; - -config.plugins = [config.plugins[0], new webpack.optimize.UglifyJsPlugin({ - sourceMap: false, - output: { - ascii_only: true - }, - compress: { - warnings: false - } -})]; - -config.module.loaders.forEach(function(loader) { - if (loader.loader === 'babel') { - // remove preset hmre - loader.query.presets = loader.query.presets.slice(0, 3); - } - return loader; -}); - -module.exports = config; diff --git a/webpack.website.config.js b/webpack.website.config.js deleted file mode 100644 index 10c58e1edc..0000000000 --- a/webpack.website.config.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = function(webpackConfig) { - webpackConfig.entry = { - index: './site/entry/index.jsx', - }; - webpackConfig.resolve.root = process.cwd(); - webpackConfig.resolve.alias = { - antd: 'index', - BrowserDemo: 'site/component/BrowserDemo', - }; - - return webpackConfig; -};