This repository has been archived by the owner on May 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
151 lines (143 loc) · 4.82 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
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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MediaQueryPlugin = require('media-query-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { InjectManifest } = require('workbox-webpack-plugin');
// const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
// const WebpackShellPlugin = require('webpack-shell-plugin');
// const exec = require('child_process').exec;
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const OfflineRequestsWebpackConfig = require('./webpack.config.offline-requests');
const CartAbandonNotificationWebpackConfig = require('./webpack.config.cart-abandon-notification');
const PushExamplesWebpackConfig = require('./webpack.config.push-examples');
const plugins = [
new HtmlWebpackPlugin({
filename: 'index.html',
favicon: './src/favicon/favicon.ico',
template: path.resolve(__dirname, 'src/index.ejs'),
chunks: ['home'],
inlineSource: 'src\/css\/.css$'
}),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, 'bower_components/webcomponentsjs/*.js'),
to: 'bower_components/webcomponentsjs/[name].[ext]'
},
{
from: path.resolve(__dirname, 'src/img'),
to: path.resolve(__dirname, 'build/img'),
},
{
from: path.resolve(__dirname, 'src/favicon'),
to: path.resolve(__dirname, 'build/favicon'),
},
'./src/offline.html',
'./src/manifest.json',
]),
new InjectManifest({
swSrc: './src/service-worker.js',
exclude: [/service-worker\.js/, /\.DS_Store$/, /\/unoptimised\/.+\.jpg/, /CNAME/, /\/pages\//],
}),
new MediaQueryPlugin({
include: true,
queries: {
'screen and (min-width: 767px)': ''
}
})
];
module.exports = [
OfflineRequestsWebpackConfig,
CartAbandonNotificationWebpackConfig,
PushExamplesWebpackConfig,
{
mode: 'none',
// Tell Webpack which file kicks off our app.
entry: {
home: path.resolve(__dirname, 'src/js/index.js'),
// ? importing from inside of home.js chunk -> tabs: path.resolve(__dirname, 'src/js/tabs.js'),
},
// Tell Weback to output our bundle.js
output: {
filename: '[name].js',
chunkFilename: '[name].js',
path: path.resolve(__dirname, 'build')
},
// Tell Webpack which directories to look in to resolve import statements.
// Normally Webpack will look in node_modules by default but since we’re overriding
// the property we’ll need to tell it to look there in addition to the
// bower_components folder.
resolve: {
modules: [
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, 'bower_components')
]
},
// These rules tell Webpack how to process different module types.
// Remember, *everything* is a module in Webpack. That includes
// CSS, and (thanks to our loader) HTML.
module: {
rules: [
{
// If you see a file that ends in .html, send it to these loaders.
test: /\.html$/,
// This is an example of chained loaders in Webpack.
// Chained loaders run last to first. So it will run
// raw-loader, then polymer-webpack-loader and finally hand the output to
// babel-loader. This let's us transpile JS in our `<script>` elements.
use: [
{ loader: 'babel-loader' },
{ loader: 'polymer-webpack-loader' },
{ loader: 'raw-loader' }
]
},
{
// If you see a file that ends in .js, just send it to the babel-loader.
test: /(^@polymer|\.js$)/,
use: 'babel-loader'
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
options: {
insert: 'head',
injectType: 'singletonStyleTag'
},
},
"css-loader",
MediaQueryPlugin.loader
]
},
{
test: /.(jpg|jpeg|png|svg)$/,
use: ['file-loader'],
},
]
},
// Enable the Webpack dev server which will build, serve, and reload our
// project on changes.
devServer: {
contentBase: __dirname,
compress: true,
port: 9000
},
plugins: [...plugins]
}
];
// filename: ({ chunk }) => {
// switch (chunk.name) {
// case 'offlineRequests':
// return 'offline-requests/[name].js'
// default:
// case 'cartAbandonNotification':
// return 'cart-abandon-notification/[name].js'
// default:
// case 'pushExamples':
// return 'push-examples/[name].js'
// default:
// return '[name].js';
// }
// },
// path: path.resolve(__dirname, 'build')