-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
68 lines (67 loc) · 1.47 KB
/
webpack.config.js
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
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const merge = require("webpack-merge");
const devserver = require("./webpack/devserver");
const sass = require("./webpack/sass");
const css = require("./webpack/css");
const cssExtractor = require("./webpack/cssExtractor");
const common = {
entry: "./src/index",
output: {
filename: "bundle.js",
path: path.join(__dirname, "dist")
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: { presets: ['stage-3', 'es2015', 'react'] }
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/, use: [{
loader: 'file-loader',
query: {
useRelativePath: process.env.NODE_ENV === "production"
}
}]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: "file-loader?publicPath=../&outputPath=css/fonts/"
},
]
},
plugins: [
new HtmlWebpackPlugin({
inject: false,
template: './src/index.ejs',
title_: "webpack test react"
}),
]
}
module.exports = function (env) {
if (env === "production") {
common.plugins.push(new webpack.optimize.UglifyJsPlugin());
common.plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}))
return merge([
common,
cssExtractor()
]);
}
if (env === "development") {
return merge([
common,
devserver(),
sass(),
css(),
{ devtool: "eval-source-map" }
])
}
}