-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwebpack.config.js
99 lines (96 loc) · 2.65 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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const webpack = require('webpack')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ImageminPlugin = require('imagemin-webpack-plugin').default
const cssNano = require('cssnano')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production'
const config = {
entry: {
popup: './app/pages/popup/popup.js',
options: './app/pages/options/options.js'
},
output: {
path: path.resolve(__dirname, './extension'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.html$/,
use: ['html-loader']
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
'file-loader?name=[name].[ext]&outputPath=images/&publicPath=images/'
]
}
]
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
//Generate an HTML5 file that includes all webpack bundles(includes css & js) in the body using script tags
new HtmlWebpackPlugin({
title: 'Cato - App',
template: './app/pages/popup/popup.html',
filename: 'popup.html',
chunks: ['popup']
}),
new HtmlWebpackPlugin({
title: 'Cato - Options',
template: './app/pages/options/options.html',
filename: 'options.html',
chunks: ['options']
}),
//Create our CSS bundles by our entry points names (Ex: popup.css, options.css)
new ExtractTextPlugin({
filename: '[name].css'
}),
new CopyWebpackPlugin([
{from: 'app/images', to: 'images'},
{from: 'app/manifest.json'}
]),
new ImageminPlugin({test: /\.(jpe?g|png|gif|svg)$/i})
]
}
if(isProduction) {
config.plugins.push(
new UglifyJSPlugin({
sourceMap: false,
uglifyOptions: {
compress: {
dead_code: true,
drop_console: true,
unused: true,
if_return: true
}
}
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/,
cssProcessor: cssNano,
cssProcessorOptions: {discardComments: {removeAll: true}}, canPrint: true
})
)
}
module.exports = config