Last active
January 10, 2018 21:05
-
-
Save SergProduction/b1c7d333aedbdf1b67ab5864fd7e4eaa 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 merge = require('webpack-merge') | |
| const WebpackBabelExternalsPlugin = require('webpack-babel-external-helpers-2') | |
| const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin | |
| const UglifyJSPlugin = require('uglifyjs-webpack-plugin') | |
| const ExtractTextPlugin = require('extract-text-webpack-plugin') | |
| const modeProd = process.env.NODE_ENV === 'prod' | |
| const extractCSS = new ExtractTextPlugin('css/olimp.css') | |
| const extractSTYLUS = new ExtractTextPlugin('css/olimp-stylus.css') | |
| const dev = { | |
| entry: { | |
| olimp: './src/index.jsx', | |
| }, | |
| output: { | |
| path: path.resolve(__dirname, 'public'), | |
| filename: '[name].js', | |
| library: '[name]', | |
| }, | |
| devtool: 'cheap-module-eval-source-map', | |
| watch: true, | |
| devServer: { | |
| contentBase: path.join(__dirname, 'public'), | |
| publicPath: '/', | |
| watchContentBase: true, | |
| historyApiFallback: { | |
| from: /\/\w/, | |
| to: '/', | |
| }, | |
| host: '0.0.0.0', | |
| port: 3000, | |
| }, | |
| } | |
| const prod = { | |
| entry: { | |
| 'olimp-prod': './src/index.jsx', | |
| }, | |
| output: { | |
| path: path.resolve(__dirname, 'public'), | |
| filename: '[name].js', | |
| }, | |
| plugins: [ | |
| new webpack.DefinePlugin({ | |
| 'process.env': { | |
| NODE_ENV: JSON.stringify('production'), | |
| }, | |
| }), | |
| // new WebpackBabelExternalsPlugin(), | |
| new UglifyJSPlugin(), | |
| ], | |
| } | |
| const analyze = merge(prod, { | |
| plugins: [ | |
| new BundleAnalyzerPlugin(), | |
| ], | |
| }) | |
| const common = { | |
| context: __dirname, | |
| resolve: { | |
| extensions: ['.js', '.jsx'], | |
| }, | |
| target: 'web', | |
| module: { | |
| rules: [ | |
| { | |
| test: /\.jsx?$/, | |
| include: [ | |
| path.resolve(__dirname, './src'), | |
| ], | |
| loader: 'babel-loader', | |
| options: { | |
| presets: ['es2015', 'react', 'flow'], | |
| plugins: [ | |
| 'transform-runtime', | |
| // 'transform-regenerator', | |
| 'transform-async-to-generator', | |
| 'transform-class-properties', | |
| 'transform-object-rest-spread', | |
| 'lodash', | |
| ], | |
| }, | |
| }, | |
| { | |
| test: /\.(png|jpg|svg)$/, | |
| loader: 'file-loader', | |
| include: /img/, | |
| options: { | |
| context: __dirname, | |
| name: modeProd | |
| ? 'img/[name].[ext]' | |
| : '[path][name].[ext]', | |
| }, | |
| }, | |
| { | |
| test: /\.(eot|svg|ttf|woff|woff2)$/, | |
| loader: 'file-loader', | |
| include: /fonts/, | |
| options: { | |
| context: __dirname, | |
| name: modeProd | |
| ? 'fonts/[name].[ext]' | |
| : '[path][name].[ext]', | |
| }, | |
| }, | |
| { | |
| test: /\.css$/, | |
| include: [ | |
| path.join(__dirname, './src'), | |
| /olimp-ui/, | |
| ], | |
| use: extractCSS.extract(['css-loader']), | |
| }, | |
| { | |
| test: /\.styl$/, | |
| include: path.join(__dirname, './src'), | |
| use: extractSTYLUS.extract([ | |
| 'css-loader', | |
| 'stylus-loader', | |
| ]), | |
| }, | |
| ], | |
| }, | |
| plugins: [ | |
| extractCSS, | |
| extractSTYLUS, | |
| ], | |
| } | |
| function mode(type) { | |
| switch (type) { | |
| case 'dev': | |
| return merge(dev, common) | |
| case 'prod': | |
| return merge(prod, common) | |
| case 'analyze': | |
| return merge(analyze, common) | |
| default: | |
| return merge(dev, common) | |
| } | |
| } | |
| module.exports = mode(process.env.NODE_ENV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment