UNPKG

2.21 kBJavaScriptView Raw
1require('dotenv').config({ silent: true });
2
3const merge = require('webpack-merge');
4const webpack = require('webpack');
5const ManifestPlugin = require('webpack-manifest-plugin');
6const ExtractTextPlugin = require('extract-text-webpack-plugin');
7const path = require('path');
8const TARGET = process.env.TARGET;
9const PATHS = {
10 build: path.join(process.cwd(), 'build')
11};
12
13const common = {
14 output: {
15 publicPath: process.env.CDN
16 },
17 plugins: [
18 new webpack.DefinePlugin({
19 'process.env': {
20 NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')
21 }
22 })
23 ],
24 module: {
25 loaders: [
26 {
27 test: /\.css$/,
28 loader: 'style-loader!css-loader?modules!postcss-loader'
29 }
30 ]
31 },
32 resolve: {
33 root: [path.resolve('.')],
34 modulesDirectories: ['node_modules', 'node_modules/reforge/node_modules']
35 },
36 postcss: require('./postcss.config.js')
37};
38
39if (TARGET === 'start') {
40 module.exports = merge(common, {});
41}
42
43if (TARGET === 'build') {
44 module.exports = merge.smart(common, {
45 entry: {
46 main: 'main.js',
47 vendor: [
48 'react',
49 'react-dom',
50 'redux',
51 'redux-saga',
52 'react-redux',
53 'react-router',
54 'react-router-redux'
55 ]
56 },
57 output: {
58 path: PATHS.build,
59 filename: '[name].[chunkhash].js',
60 publicPath: process.env.CDN
61 },
62 resolve: {
63 alias: {
64 'react': 'react-lite',
65 'react-dom': 'react-lite'
66 }
67 },
68 module: {
69 loaders: [
70 {
71 test: /\.css$/,
72 // Extract text needs text not a javascript module, so leave off style-loader
73 loader: ExtractTextPlugin.extract('css-loader?modules!postcss-loader')
74 }
75 ]
76 },
77 plugins: [
78 //new webpack.IgnorePlugin(/babel-polyfill/),
79 new webpack.optimize.CommonsChunkPlugin({
80 name: 'vendor',
81 minChunks: Infinity
82 }),
83 new ManifestPlugin({ filename: 'manifest.json' }),
84 new webpack.optimize.OccurrenceOrderPlugin(),
85 new webpack.optimize.UglifyJsPlugin({sourceMap: false, compress: {warnings: false}}),
86 new ExtractTextPlugin('[name].[chunkhash].css')
87 ]
88 });
89}