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
|
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const SRC_PATH = path.join(__dirname, '..', 'src')
const BUILD_PATH = path.join(__dirname, '..', 'build', 'static')
const PUBLIC_PATH = path.join(__dirname, '..', 'public')
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: BUILD_PATH
},
module: {
rules: [{
test: /\.(js|jsx)$/,
use: ['eslint-loader'],
include: SRC_PATH
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: ['css-loader']
})
},
{
test: /\.css\.js$/,
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('autoprefixer')]
}
}]
})
},
{
test: /\.css\.js$/,
use: ['css-js-loader']
},
{
test: /\.(js|jsx)$/,
include: SRC_PATH,
use: [{
loader: 'babel-loader',
query: {
presets: [
'es2015',
'react'
],
cacheDirectory: true
}
}]
}]
},
plugins: [
new ExtractTextPlugin('style.css'),
new HtmlWebpackPlugin({
template: path.join(PUBLIC_PATH, 'index.html'),
filename: '../index.html',
inject: 'body'
})
]
}
if(process.env.NODE_ENV === 'production') module.exports.plugins.push(new UglifyJSPlugin())
|