-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
149 lines (134 loc) · 3.74 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const _ = require('lodash');
const path = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const tsloader = require('awesome-typescript-loader');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
// TODO production config
const NODE_ENV = process.env.NODE_ENV || 'development';
const PROD = NODE_ENV === 'production';
const extractCSS = new ExtractTextPlugin('styles.css');
const plugins = [
extractCSS,
new tsloader.TsConfigPathsPlugin(),
/*
* Plugin: ForkCheckerPlugin
* Description: Do type checking in a separate process, so webpack doesn't need to wait.
*
* See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
*/
new tsloader.CheckerPlugin(),
/*
* Plugin: CommonsChunkPlugin
* Description: Shares common code between the pages.
* It identifies common modules and puts them into a commons chunk.
*
* See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
* See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
*/
new webpack.optimize.CommonsChunkPlugin({
name: ['hmr', 'polyfills', 'vendor']
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(NODE_ENV),
},
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
}),
// Uncomment to minify the production bundles.
// PROD ? new webpack.optimize.UglifyJsPlugin(uglifyOptions) : null,
].filter(_.identity);
const rules = [
{
test: /\.json$/,
loader: 'json',
},
{
test: /\.jsx?$/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
}
},
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
},
{
test: /\.scss$/,
loader: extractCSS.extract([
{
loader: 'css-loader',
query: {
sourceMap: true,
modules: true,
importLoaders: 1,
localIdentName: '[local]',
}
},
'postcss-loader',
]),
},
// "file" loader makes sure those assets get served by WebpackDevServer.
// When you `import` an asset, you get its (virtual) filename.
// In production, they would get copied to the `build` folder.
{
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
loader: 'file',
query: {
name: 'static/media/[name].[hash:8].[ext]'
}
},
// "url" loader works just like "file" loader but it also embeds
// assets smaller than specified size as data URLs to avoid requests.
{
test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
loader: 'url',
query: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]'
}
}
];
module.exports = {
devtool: 'source-map',
entry: {
vendor: [
'webpack-hot-middleware/client',
// isomorphic polyfills
'./polyfills',
// vendor dependencies
'./vendor.browser.js'
],
// app entry point
app: './src/client/index.tsx'
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.css', '.scss', '.less'],
alias: {
'semantic-ui-react': 'semantic-ui-react/src/index.js',
}
},
module: {
rules: rules, // eslint-disable-line
},
plugins: plugins, // eslint-disable-line
output: {
path: path.join(__dirname, 'dist'),
/**
* Specifies the name of each output file on disk.
* IMPORTANT: You must not specify an absolute path here!
*
* See: http://webpack.github.io/docs/configuration.html#output-filename
*/
filename: '[name].bundle.js',
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
publicPath: '/dist/',
}
};