-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
130 lines (120 loc) · 3.29 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
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
127
128
129
130
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const base = {
entry: ['./src/index.tsx'],
output: {
filename: './bundle.js',
path: __dirname + '/dist'
},
// Enable sourcemaps for debugging webpack's output.
devtool: 'source-map',
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
src: path.resolve(__dirname, './src')
}
},
externals: {
jquery: 'window.$'
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
loaders: ['react-hot-loader/webpack', 'awesome-typescript-loader']
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader'
},
// Style
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader']
},
// images
{
test: /\.(?:png|jpe?g|gif|ico)$/,
loader: 'url-loader',
query: {
limit: 8192,
name: 'images/[name].[hash:8].[ext]'
}
},
{
test: /\.(?:woff2?|eot|ttf|otf|svg)$/,
loader: 'url-loader',
query: {
limit: 8192,
name: 'fonts/[name].[hash:8].[ext]'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
title: 'My App',
template: './src/index.html',
filename: 'index.html'
}),
new webpack.NamedModulesPlugin(),
new ProgressBarPlugin(),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, './node_modules/materialize-css/dist'),
to: path.resolve(__dirname, './dist/materialize'),
ignore: ['.*']
}
]),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, './node_modules/jquery/dist/jquery.min.js'),
to: path.resolve(__dirname, './dist/materialize/js'),
ignore: ['.*']
}
])
]
}
let config = base;
if (process.env.NODE_ENV == 'production') {
config = Object.assign({}, base, {
output: {
filename: './[hash:8].bundle.js',
path: __dirname + '/dist'
},
devtool: false,
plugins: base.plugins.concat([
new CleanWebpackPlugin([path.resolve(__dirname, './dist')], {
allowExternal: true,
exclude: ['.git']
}),
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.NoEmitOnErrorsPlugin()
])
});
} else {
config = Object.assign({}, base, {
// Enable sourcemaps for debugging webpack's output.
devtool: 'source-map',
entry: ['react-hot-loader/patch', './src/index.tsx'],
plugins: base.plugins.concat([
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
])
});
}
module.exports = config;