chore: merge webpack config into one file

This commit is contained in:
Benjy Cui 2016-03-23 15:43:23 +08:00
parent cd39283aca
commit 66abe72462
5 changed files with 34 additions and 128 deletions

View File

@ -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",

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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;

View File

@ -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;
};