Last active
April 1, 2018 00:09
-
-
Save kejun/a035af7ef00b245587753c5bcaa2ec0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); | |
const CleanPlugin = require('clean-webpack-plugin'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const extractSass = new ExtractTextPlugin({ | |
filename: 'css/[name].css' | |
}); | |
const jsBuildPath = path.resolve(__dirname, 'dist'); | |
const js_rules = { | |
test: /.js$/, | |
use: { | |
loader: 'babel-loader' | |
} | |
}; | |
const css_rules = { | |
test: /.scss$/, | |
use: extractSass.extract({ | |
use: [ | |
{ | |
loader: 'css-loader', | |
options: { | |
minimize: process.env.NODE_ENV === 'production' | |
} | |
}, | |
{ | |
loader: 'postcss-loader' | |
}, | |
{ | |
loader: 'sass-loader' | |
} | |
] | |
}) | |
}; | |
const config = { | |
entry: { | |
index: [ | |
path.resolve(__dirname, 'js/shim.js'), | |
path.resolve(__dirname, 'js/index.js') | |
], | |
event: [ | |
path.resolve(__dirname, 'js/shim.js'), | |
path.resolve(__dirname, 'js/event.js') | |
] | |
}, | |
output: { | |
publicPath: '/static/', | |
path: jsBuildPath, | |
filename: 'js/[name].js' | |
}, | |
module: { | |
rules: [ | |
js_rules, | |
css_rules, | |
] | |
}, | |
resolve: { | |
alias: { | |
css: path.resolve(__dirname, 'css'), | |
pics: path.resolve(__dirname, 'pics') | |
} | |
}, | |
plugins: [ | |
new webpack.optimize.ModuleConcatenationPlugin(), | |
new webpack.LoaderOptionsPlugin({ | |
test: /\.scss$/i, | |
options: { | |
postcss: { | |
plugins: [ | |
require('autoprefixer')({ browsers: ['> 0.2%'] }), | |
require('postcss-write-svg'), | |
require('postcss-inline-svg'), | |
require('postcss-svgo'), | |
], | |
} | |
} | |
}), | |
new CleanPlugin([jsBuildPath]), | |
extractSass, | |
new webpack.DefinePlugin({ | |
'process.env': { NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development') } | |
}) | |
].concat( | |
process.env.NODE_ENV === 'production' ? [ | |
new webpack.optimize.UglifyJsPlugin({ | |
beautify: false, | |
mangle: { | |
screw_ie8: true, | |
keep_fnames: true | |
}, | |
compress: { | |
screw_ie8: true | |
}, | |
comments: false | |
}) | |
] : [] | |
), | |
devServer: { | |
contentBase: [ | |
path.join(__dirname, "pages"), | |
], | |
hot: false, | |
compress: true, | |
allowedHosts: [ | |
'frodo.douban.com' | |
], | |
headers: { | |
'Access-Control-Allow-Origin': '*' | |
}, | |
clientLogLevel: 'none', | |
proxy: { | |
"/event": { | |
bypass: function(req, res, options) { | |
if ((/^\/event/i).test(req.url)) { | |
return '/event.html' | |
} | |
} | |
} | |
}, | |
port: 8090 | |
}, | |
externals: { | |
react: 'React', | |
'react-dom': 'ReactDOM', | |
immutable: 'Immutable' | |
}, | |
devtool: 'source-map' | |
}; | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment