forked from clhenrick/metronome-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.common.js
156 lines (146 loc) · 4.34 KB
/
webpack.config.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
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
150
151
152
153
154
155
156
/* eslint-disable */
// webpack configuration common to both production and development
const metadata = require('./package.json');
const path = require('path');
const webpack = require('webpack');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractSass = new ExtractTextPlugin({
filename: '[name].[hash].css',
disable: process.env.NODE_ENV === 'development',
});
module.exports = {
// where the compiled code is placed
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[hash].js',
},
resolve: {
extensions: ['.js', '.jsx', '.json', '.geojson'],
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
},
// what to do with different types of modules, e.g. sass, js, jsx, json, geojson
module: {
rules: [
// handles web-workers
{
test: /worker\.js$/,
use: [
{
loader: 'worker-loader',
options: {
name: 'worker.[hash].js',
inline: true,
},
},
{
loader: 'babel-loader',
},
],
},
// Lint JS and transpile ES6 to ES5
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
}
],
},
// Use Sass and transpile to CSS
{
test: /\.(css|scss)$/,
use:
process.env.NODE_ENV !== 'production'
? [
{
loader: 'style-loader', // creates style nodes from JS strings
},
{
loader: 'css-loader', // translates CSS into CommonJS
},
{
loader: 'postcss-loader', // postcss loader so we can use autoprefixer
options: {
config: {
path: 'postcss.config.js',
},
},
},
{
loader: 'sass-loader', // compiles Sass to CSS
},
]
: extractSass.extract({
use: [
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
fallback: [
{
loader: 'style-loader',
},
],
}),
},
// allows for using ES6 (dynamic) imports for JSON and GeoJSON files, no async loading!
{
test: /\.(json|geojson)$/,
use: 'json-loader',
},
// load images
// url-loader will base64 encode images smaller than options.limit
// otherwise it behaves just like file-loader
{
test: /\.(jpe?g|png|gif|svg)$/,
loader: 'url-loader',
options: {
limit: 8192,
},
},
// load local fonts if they exist
// for more info see https://survivejs.com/webpack/loading/fonts/
{
test: /\.(eot|ttf|woff|woff2)$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
},
],
},
plugins: [
// set environment variables which can be used in source code
new webpack.DefinePlugin({
'process.env.IMMERSE_BUILD_MODE': JSON.stringify(process.env.IMMERSE_BUILD_MODE),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.APP_VERSION': JSON.stringify(metadata.version),
}),
extractSass,
// codesplitting: vendor libraries
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function(module) {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf('node_modules') !== -1;
},
}),
// codesplitting: source
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity,
}),
// allows for appending script and link tags for bundled JS and CSS
new HTMLWebpackPlugin({
template: 'src/index.html',
}),
// desktop notification when webpack updates
new WebpackNotifierPlugin({ alwaysNotify: true }),
],
};