1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const InterpolateHtmlPlugin = require('interpolate-html-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const joinDir = dir => path.join(__dirname, '..', dir)
const SRC_PATH = joinDir('src')
const BUILD_PATH = joinDir('build')
const PUBLIC_PATH = joinDir('public')
const NODE_PATH = joinDir('node_modules')
const FILE_FORMAT = '[name].[hash:8].[ext]'
const isProduction = process.env.NODE_ENV === 'production'
module.exports = {
devtool: isProduction ? false : 'cheap-eval-source-map',
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: BUILD_PATH
},
module: {
rules: [
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, // load the fonts
use: [{
loader: 'file-loader',
query: {
name: path.join('fonts', FILE_FORMAT)
}
}]
},
{
exclude: [ // load other static assets
/\.ttf$/,
/\.eot$/,
/\.html$/,
/\.(js|jsx)$/,
/\.css$/,
/\.json$/,
/\.svg$/
],
use: [{
loader:'url-loader',
query: {
limit: 10000,
name: path.join('media', FILE_FORMAT)
}
}]
},
{
test: /\.css$/, // load css libs without css modules or postcss
include: NODE_PATH,
use: ExtractTextPlugin.extract({
use: ['css-loader']
})
},
{
test: /\.(css\.js|css)$/, // TODO remove .css.js from regex after migrating
include: SRC_PATH,
use: ExtractTextPlugin.extract({
use: [{
loader: 'css-loader',
query: {
modules: true,
importLoaders: 1,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
},
{
loader: 'postcss-loader',
options:{
plugins: () => [
require('postcss-nesting'),
require('postcss-cssnext'),
require('precss')
]
}
}]
})
},
{
test: /\.css\.js$/, // TODO remove after migrating to postcss
use: ['css-js-loader']
},
{
test: /\.(js|jsx)$/,
include: SRC_PATH,
use: [{
loader: 'babel-loader',
options: {
plugins: ['transform-decorators-legacy'],
presets: [
'es2015',
'react'
],
cacheDirectory: true
}
}]
},
{
test: /\.(js|jsx)$/, // lint the js before babel
enforce: 'pre',
use: ['eslint-loader'],
include: SRC_PATH
}]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}),
new ExtractTextPlugin('style.css'),
new InterpolateHtmlPlugin({
APP_TITLE: process.env.APP_TITLE
}),
new HtmlWebpackPlugin({
template: path.join(PUBLIC_PATH, 'index.html'),
inject: 'body'
})
]
}
if(isProduction) module.exports.plugins.push(new webpack.optimize.UglifyJsPlugin())
|