-
Notifications
You must be signed in to change notification settings - Fork 174
/
.webpackrc.js
73 lines (70 loc) · 2.05 KB
/
.webpackrc.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
// Learn more about configuring Webpack
// https://webpack.js.org/concepts/
import dotenv from "dotenv"
import fs from "fs"
import webpack from "webpack"
/**
* Load env vars from .env if available
*/
dotenv.config()
export default function(env) {
const isProduction = (env === "production") || (process.env.NODE_ENV === "production")
return {
output: {
path: __dirname + "/js/",
filename: "[name].js"
},
externals: {
// Any third-party deps added via a <script> tag
// can be defined here so that they can be required
// in your application's JS files
"instantsearch.js": "instantsearch",
"moment": "moment"
},
resolve: {
// Can be used to create aliases for imports
// modules: path.resolve(__dirname, 'src/js/example/utilities/')
// => import * from "utilities/filename"
},
module: {
rules: [
{
// Enables ES6 syntax for JS
loader: "babel-loader",
test: /\.js?$/,
exclude: /node_modules/,
query: {cacheDirectory: true}
},
{
// Enable importing HTML files
test: /\.(html)$/,
use: {
loader: "html-loader",
options: {
attrs: [":data-src", ":data-srcset"]
}
}
}
// TODO: add eslint-loader to fail builds
// with invalid browser code
]
},
devtool: (isProduction) ? "nosources-source-map" : "cheap-eval-source-map",
plugins: [
new webpack.ProvidePlugin({
// Automatically make packages available
// without having to require them
fetch: "imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch"
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
}),
new webpack.DefinePlugin({
// Provide enviroment variable defaults
// from .env.js
ALGOLIA_APP_ID: JSON.stringify(process.env.ALGOLIA_APP_ID),
ALGOLIA_SEARCH_KEY: JSON.stringify(process.env.ALGOLIA_SEARCH_KEY)
})
]
}
}