-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.production.config.js
125 lines (115 loc) · 4.13 KB
/
webpack.production.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
const path = require('path');
const webpack = require('webpack');
const swPrecache = require('sw-precache');
const packageJson = require('./package.json');
function WebpackSwPrecachePlugin(options) {
}
WebpackSwPrecachePlugin.prototype.apply = function(compiler) {
var rootDir = 'static';
var defaultOptions = {
cacheId: packageJson.name,
//directoryIndex: "index.html",
// dynamicUrlToDependencies: {
// '/app/efle3r': [
// path.join(rootDir, 'views', 'index.html')
// ]
// },
// If handleFetch is false (i.e. because this is called from generate-service-worker-dev), then
// the service worker will precache resources but won't actually serve them.
// This allows you to test precaching behavior without worry about the cache preventing your
// local changes from being picked up during the development cycle.
handleFetch: true,
importScripts: ['sw-toolbox-config.js'],
//logger: function,
maximumFileSizeToCacheInBytes: 10485760, //10MB
//navigateFallback: "index.html",
//navigateFallbackWhitelist: [/^\/guide\//],
// runtimeCaching: [{
// // See https://github.com/GoogleChrome/sw-toolbox#methods
// urlPattern: /runtime-caching/,
// handler: 'cacheFirst',
// // See https://github.com/GoogleChrome/sw-toolbox#options
// options: {
// cache: {
// maxEntries: 1,
// name: 'runtime-cache'
// }
// }
// }],
replacePrefix: "/app/pager",
staticFileGlobs: [
//rootDir + '/**/*.{js,json,css,png,jpg,gif,svg,eot,ttf,woff}'
rootDir + '/css/**/*.css',
rootDir + '/index.html',
rootDir + '/images/**/*',
rootDir + '/js/bundle.js',
rootDir + '/js/localforage.min.js',
rootDir + '/js/register-service-worker.js',
rootDir + '/js/sw-toolbox.js',
rootDir + '/*.json'
],
stripPrefix: rootDir,
verbose: true
}
compiler.plugin("after-emit", (compilation, callback) => {
swPrecache.write(path.join(rootDir,"sw-precache-config.js"), defaultOptions, function(err){
if (err) {
console.log("\n*** sw-precache file creation error: "+err)
} else {
console.log("\nCreated sw-precache file static/sw-precache-config.js")
}
callback(err);
})
});
};
module.exports = {
entry: __dirname + '/src/index.js',
output: {
path: __dirname + "/static/js",
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel'
},
{
test: /\.scss$/,
loader: 'style!css!sass'
},
{
test: /\.css$/,
loader: 'style!css?modules!postcss'
}
],
resolve: {
modulesDirectories: ['node_modules'],
alias: {},
extensions: ['', '.js', '.jsx']
}
},
postcss: [
require('autoprefixer')
],
plugins: [
new webpack.BannerPlugin("Copyright Colloqi Consulting(OPC) Pvt Ltd."),
/**
* NoErrorsPlugin prevents your webpack CLI from exiting with an error code if
* there are errors during compiling - essentially, assets that include errors
* will not be emitted. If you want your webpack to 'fail', you need to check out
* the bail option.
*/
new webpack.NoErrorsPlugin(),
/**
* DefinePlugin allows us to define free variables, in any webpack build, you can
* use it to create separate builds with debug logging or adding global constants!
* Here, we use it to specify a development build.
*/
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new WebpackSwPrecachePlugin()
]
};