This repository has been archived by the owner on Aug 15, 2019. It is now read-only.
/
webpack.config.js
102 lines (88 loc) · 2.61 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
const { resolve } = require('path');
const webpack = require('webpack');
const findCacheDir = require('find-cache-dir');
const objectHash = require('node-object-hash');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
devtool: 'sourcemap',
context: resolve(__dirname, 'src'),
entry: [
'./index.jsx',
],
output: {
filename: 'bundle.js',
// the output bundle
path: resolve(__dirname, 'dist'),
},
externals: {
WP_API_Settings: 'WP_API_Settings'
},
module: {
rules: [
{
test: /\.jsx?$/,
use: [
{
loader: 'babel-loader',
options: {
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/react-scripts/
// directory for faster rebuilds. We use findCacheDir() because of:
// https://github.com/facebookincubator/create-react-app/issues/483
cacheDirectory: findCacheDir({
name: 'react-scripts'
})
}
}
],
exclude: /node_modules/
},
{
test: /\.styl$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[path]--[local]--[hash:base64:5]'
}
},
{
loader: 'postcss-loader', // See postcss.config.js for options
},
{
loader: 'stylus-loader',
}
],
})
},
{
test: /\.(png|svg|jpg|gif)$/,
loader: 'url-loader?limit=10000'
}
],
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
new ExtractTextPlugin('bundle.css'),
// Minimize
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
// Use hard source caching for faster rebuilds
new HardSourceWebpackPlugin({
cacheDirectory: resolve(__dirname, '.cache/webpack-source/[confighash]'),
recordsPath: resolve(__dirname, '.cache/webpack-source/[confighash]', 'records.json'),
// Build a string value used by HardSource to determine which cache to
// use if [confighash] is in cacheDirectory, or if the cache should be
// replaced if [confighash] does not appear in cacheDirectory.
configHash: (webpackConfig) => objectHash().hash(webpackConfig)
}),
],
};