forked from solobat/paodin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
134 lines (131 loc) · 3.74 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
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: {
content: './extension/pages/content/content.js',
translate: './extension/pages/translate/translate.js',
popup: './extension/pages/popup/popup.js',
options: './extension/pages/options/options.js',
background: './extension/pages/background/background.js'
},
output: {
path: path.resolve(__dirname, './output'),
filename: '[name].js'
},
resolve: {
alias: {
vue: 'vue/dist/vue.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: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
loader: 'file-loader'
},
{
test: /\.(jpe?g|png|gif)$/i,
use: [
'file-loader?name=[name].[ext]&outputPath=img/&publicPath=./'
]
}
]
},
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: 'WordCard - Content',
template: './extension/pages/content/content.html',
filename: 'content.html',
chunks: ['content']
}),
new HtmlWebpackPlugin({
title: 'WordCard - translate',
template: './extension/pages/translate/translate.html',
filename: 'translate.html',
chunks: ['translate']
}),
new HtmlWebpackPlugin({
title: 'WordCard - Background',
template: './extension/pages/background/background.html',
filename: 'background.html',
chunks: ['background']
}),
new HtmlWebpackPlugin({
title: 'WordCard - Popup',
template: './extension/pages/popup/popup.html',
filename: 'popup.html',
chunks: ['popup']
}),
new HtmlWebpackPlugin({
title: 'WordCard - Options',
template: './extension/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: 'extension/img', to: 'img'},
{from: 'extension/css', to: 'css'},
{from: 'extension/manifest.json'}
]),
new ImageminPlugin({test: /\.(jpe?g|png|gif|svg)$/i})
]
}
if(isProduction) {
config.plugins.push(
new UglifyJSPlugin({
sourceMap: false,
uglifyOptions: {
mangle: true,
compress: {
dead_code: true,
drop_console: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true
}
}
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/,
cssProcessor: cssNano,
cssProcessorOptions: {discardComments: {removeAll: true}, safe: true}, canPrint: true
})
)
}
module.exports = config