This repository has been archived by the owner on Mar 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.js
executable file
·138 lines (137 loc) · 3.65 KB
/
webpack.dev.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
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const WebpackPwaManifest = require('webpack-pwa-manifest');
const OfflinePlugin = require('offline-plugin');
const WriteFilePlugin = require('write-file-webpack-plugin');
module.exports = {
devtool: 'cheap-module-source-map',
devServer: {
historyApiFallback: true, // This will make the server understand '/some-link' routs instead of '/#/some-link'
headers: {
'Access-Control-Allow-Origin': '*'
},
hot: true,
port: 3000,
},
entry: {
bundle: './src/app.jsx',
editor: './src/editor.js',
},
output: {
path: path.join(__dirname, 'wp-content/themes/wp-react-theme/build'),
filename: '[name].js',
publicPath: '/wp-content/themes/wp-react-theme/build/',
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
loaders: [
{
enforce: 'pre',
test: /\.jsx?$/,
// Skip any files outside of your project's `src` directory
include: [
path.resolve(__dirname, 'src'),
],
loader: 'eslint-loader',
},
{
test: /\.jsx?$/,
include: [
path.resolve(__dirname, 'src'),
],
loader: 'react-hot-loader',
},
{
test: /\.jsx?$/,
// Skip any files outside of your project's `src` directory
include: [
path.resolve(__dirname, 'src'),
],
loader: 'babel-loader',
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
},
],
}),
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file-loader?name=fonts/[name].[ext]',
},
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(), // Hot reloading
new webpack.NoEmitOnErrorsPlugin(), // Webpack will let you know if there are any errors
new ExtractTextPlugin('[name].css'),
new StyleLintPlugin({
configFile: '.stylelintrc',
context: 'src',
files: '**/*.scss',
}),
// TODO Uncomment and adjust to your needs
// new WebpackPwaManifest({
// fingerprints: false,
// name: 'name',
// short_name: 'short_name',
// description: 'description',
// background_color: '#f9f6f6',
// theme_color: '#5a3a3b',
// icons: [
// {
// src: path.resolve('src/icon.png'),
// sizes: [16, 48, 72, 96, 144, 168, 192, 512],
// },
// ],
// }),
new OfflinePlugin({
externals: [
'/',
'https://cdnjs.cloudflare.com/ajax/libs/picturefill/3.0.3/picturefill.min.js',
],
ServiceWorker: {
entry: './sw-handler.js',
publicPath: '/sw.js',
output: '../../../../sw.js',
},
AppCache: {
publicPath: '/appcache/',
directory: '../../../../appcache/',
// TODO adjust to your needs
FALLBACK: {
'/sample-page': '/',
'/contact': '/',
},
},
autoUpdate: true,
// TODO adjust to your needs
cacheMaps: [
{
match: /(\/sample-page|\/contact)\/?$/,
to: '/',
requestTypes: ['navigate'],
},
],
}),
new WriteFilePlugin({
// write only Service Worker and App Cache files
test: /(sw\.js|manifest\.appcache|manifest\.html)$/,
useHashIndex: false
}),
],
};