|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const _ = require('lodash') |
| 4 | +const path = require('path') |
| 5 | +const webpack = require('webpack') |
| 6 | +const FaviconsWebpackPlugin = require('favicons-webpack-plugin') |
| 7 | +const ExtractCssChunks = require('extract-css-chunks-webpack-plugin') |
| 8 | +const HtmlWebpackPlugin = require('html-webpack-plugin') |
| 9 | + |
| 10 | +const constants = require('../constants') |
| 11 | + |
| 12 | +const dirname = path.resolve(__dirname, '../..') |
| 13 | + |
| 14 | +module.exports = { |
| 15 | + context: dirname, |
| 16 | + |
| 17 | + entry: [ |
| 18 | + './src/styles/main.scss', |
| 19 | + './src/index' |
| 20 | + ], |
| 21 | + |
| 22 | + output: { |
| 23 | + path : path.join(dirname, '/dist'), |
| 24 | + filename : '[name].[hash].js', |
| 25 | + chunkFilename : '[name].[hash].js', |
| 26 | + publicPath : '/' |
| 27 | + }, |
| 28 | + |
| 29 | + module: { |
| 30 | + rules: [{ |
| 31 | + test: /\.(js|jsx)$/, |
| 32 | + loader: 'babel-loader', |
| 33 | + exclude: /node_modules\/(?!appirio-tech.*|topcoder|tc-)/, |
| 34 | + options: { |
| 35 | + babelrc: false, |
| 36 | + presets: [ 'env', 'react', 'stage-2' ], |
| 37 | + plugins: [ 'lodash' ] |
| 38 | + } |
| 39 | + }, { |
| 40 | + test: /\.(coffee|litcoffee|cjsx)$/, |
| 41 | + use: [ |
| 42 | + { |
| 43 | + loader: 'babel-loader', |
| 44 | + options: { |
| 45 | + babelrc: false, |
| 46 | + presets: [ 'env', 'react', 'stage-2' ], |
| 47 | + plugins: [ 'lodash' ] |
| 48 | + } |
| 49 | + }, |
| 50 | + 'coffee-loader', |
| 51 | + 'cjsx-loader' |
| 52 | + ] |
| 53 | + }, { |
| 54 | + test: /\.json$/, |
| 55 | + loader: 'json-loader' |
| 56 | + }, { |
| 57 | + /* We have to support css loading for third-party plugins, |
| 58 | + * we are not supposed to use css files inside the project. */ |
| 59 | + test: /\.css$/, |
| 60 | + use: ExtractCssChunks.extract({ |
| 61 | + fallback: 'style-loader', |
| 62 | + use: ['css-loader'] |
| 63 | + }) |
| 64 | + }, { |
| 65 | + // ASSET LOADER |
| 66 | + // Copy png, jpg, jpeg, gif, svg, woff, woff2, ttf, eot files to output |
| 67 | + // Rename the file using the asset hash |
| 68 | + // Pass along the updated reference to your code |
| 69 | + // You can add here any file extension you want to get copied to your output |
| 70 | + test: /\.(png|jpg|jpeg|gif)$/, |
| 71 | + loader: 'file-loader' |
| 72 | + }, { |
| 73 | + test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, |
| 74 | + loader: 'file-loader' |
| 75 | + }, { |
| 76 | + test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, |
| 77 | + loader: 'file-loader' |
| 78 | + }] |
| 79 | + |
| 80 | + }, |
| 81 | + |
| 82 | + resolve: { |
| 83 | + extensions: [ |
| 84 | + '.js', |
| 85 | + '.jsx', |
| 86 | + '.json', |
| 87 | + '.coffee', |
| 88 | + '.scss', |
| 89 | + '.svg', |
| 90 | + '.png', |
| 91 | + '.gif', |
| 92 | + '.jpg', |
| 93 | + '.cjsx' |
| 94 | + ] |
| 95 | + }, |
| 96 | + |
| 97 | + plugins: [ |
| 98 | + new webpack.DefinePlugin({ |
| 99 | + 'process.env': _.mapValues(constants, (value) => JSON.stringify(value)) |
| 100 | + }), |
| 101 | + new FaviconsWebpackPlugin({ |
| 102 | + logo: './src/favicon.png', |
| 103 | + // disable cache, otherwise when there is a dist folder with icons |
| 104 | + // icons don't wanna be generated in memory using webpack-dev-server |
| 105 | + persistentCache: false |
| 106 | + }), |
| 107 | + new HtmlWebpackPlugin({ |
| 108 | + template: path.join(dirname, '/src/index.html'), |
| 109 | + inject: 'body' |
| 110 | + }), |
| 111 | + // Only emit files when there are no errors |
| 112 | + new webpack.NoEmitOnErrorsPlugin(), |
| 113 | + new ExtractCssChunks({ |
| 114 | + filename: '[name].css', |
| 115 | + justExtract: true |
| 116 | + }) |
| 117 | + ] |
| 118 | +} |
0 commit comments