-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
109 lines (108 loc) · 3.01 KB
/
webpack.common.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
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
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const outputDir = path.resolve(__dirname, 'dist');
const nodeEnv = process.env.NODE_ENV;
module.exports = {
entry: {
app: ['./src/index.jsx'],
},
output: {
path: outputDir,
filename: 'bundle.js',
publicPath: '/',
},
plugins: [
new CleanWebpackPlugin([outputDir]),
// Automatically generate an HTML5 file for you that includes all your webpack bundles
new HtmlWebpackPlugin({
title: 'GraphQL Boilerplate',
favicon: './src/assets/favicon.ico',
template: './src/index.html',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(nodeEnv),
}),
],
resolve: {
extensions: ['.mjs', '.js', '.jsx'],
// Tell webpack what directories should be searched when resolving modules.
modules: ['node_modules'],
},
module: {
rules: [
// load image
{
test: /\.(png|svg|jpg|jpeg|gif)$/,
use: ['file-loader'],
},
// load font
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: ['file-loader'],
},
// load css file
{
test: /\.css$/,
loader: [
// extract CSS into separate files
nodeEnv === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
],
},
// load scss file
{
test: /\.(scss|sass)$/,
loader: [
nodeEnv === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'sass-loader',
],
},
// load javascript/react components
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
// let RHL patch React-DOM to enable hot loading
{
test: /\.(js|jsx)$/,
include: /node_modules/,
use: ['react-hot-loader/webpack'],
},
// load local less file
// {
// test: /\.less$/,
// include: [
// path.resolve(__dirname, 'src/renderer'),
// ],
// loader: [
// // extract CSS into separate files
// env.NODE_ENV === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
// // allow importing css files
// {
// loader: 'css-loader',
// options: {
// modules: true,
// sourceMap: true,
// importLoaders: 1,
// localIdentName: '[name]_[local]_[hash:base64:5]',
// },
// },
// // compile less to css
// 'less-loader',
// ],
// },
// load graphql query file
// {
// test: /\.(graphql|gql)$/,
// exclude: /node_modules/,
// loader: 'graphql-tag/loader',
// },
],
},
};