Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import webpack from 'webpack'
- import path from 'path'
- import HtmlWebpackPlugin from 'html-webpack-plugin'
- import autoprefixer from 'autoprefixer'
- import ExtractTextPlugin from 'extract-text-webpack-plugin'
- const LAUNCH_COMMAND = process.env.npm_lifecycle_event
- const isProduction = LAUNCH_COMMAND === 'production'
- process.env.BABEL_ENV = LAUNCH_COMMAND
- const PATHS = {
- root: path.join(__dirname),
- app: path.join(__dirname, 'app'),
- build: path.join(__dirname, 'dist')
- }
- const HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
- template: PATHS.app + '/index.html',
- filename: 'index.html',
- inject: 'body'
- })
- const productionPlugin = new webpack.DefinePlugin({
- 'process.env': {
- NODE_ENV: JSON.stringify('production')
- }
- })
- const productionPlugin2 = new webpack.optimize.UglifyJsPlugin({
- compressor: {
- warnings: false
- }
- })
- const productionPlugin3 = new ExtractTextPlugin('style.css')
- const base = {
- entry: [
- 'babel-polyfill',
- PATHS.app
- ],
- output: {
- path: PATHS.build,
- filename: 'index_bundle.js'
- },
- postcss: [ autoprefixer({ browsers: ['last 2 versions'] }) ],
- resolve: {
- root: path.resolve('./app')
- }
- }
- const developmentConfig = {
- devtool: 'cheap-module-inline-source-map',
- module: {
- loaders: [
- {test: /.js$/, exclude: /node_modules/, loader: 'babel-loader'},
- {test: /.css$/, loader: 'style!css?sourceMap&modules&localIdentName=[name]__[local]___[hash:base64:5]&importLoader=1!postcss'}
- ]
- },
- devServer: {
- contentBase: PATHS.build,
- historyApiFallback: true,
- hot: true,
- inline: true,
- progress: true
- },
- plugins: [HTMLWebpackPluginConfig, new webpack.HotModuleReplacementPlugin()]
- }
- const productionConfig = {
- devtool: 'cheap-module-source-map',
- module: {
- loaders: [
- {test: /.js$/, exclude: /node_modules/, loader: 'babel-loader'},
- { test: /.css$/, loader: ExtractTextPlugin.extract('css?sourceMap&modules&localIdentName=[name]__[local]___[hash:base64:5]&importLoader=1!postcss') }
- ]
- },
- plugins: [HTMLWebpackPluginConfig, productionPlugin, productionPlugin2, productionPlugin3]
- }
- export default Object.assign({}, base, isProduction === true ? productionConfig : developmentConfig)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement