-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwebpack.config.js
62 lines (55 loc) · 1.84 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
const path = require('path')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const HTMLWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
const merge = require('webpack-merge')
const sourceDirectory = path.resolve(__dirname, './src')
const buildDirectory = path.resolve(__dirname, './dist')
const devConfig = require('./webpack/webpack.dev.js')
const prodConfig = require('./webpack/webpack.prod.js')
const rules = require('./webpack/webpack.loaders.js')
const cssFontPlugin = new ExtractTextPlugin('./css/[name].fonts.[hash:8].css')
const scssPlugin = new ExtractTextPlugin('./css/[name].styles.[hash:8].css')
const commonConfig = {
entry: ['@babel/polyfill', sourceDirectory.concat('/index.js')],
output: {
path: buildDirectory,
publicPath: '/',
filename: '[name].bundle.min.js'
},
plugins: [
// new CleanWebpackPlugin(buildDirectory),
new HTMLWebpackPlugin({
template: './public/index.html',
filename: 'index.html',
inject: 'body'
}),
new ServiceWorkerWebpackPlugin({
entry: path.join(__dirname, 'src/sw.js'),
}),
cssFontPlugin,
scssPlugin,
new CopyWebpackPlugin([
{ from: './public/img', to: './img' }/* ,
{
from: './node_modules/@coreui/react/React_Full_Project/public/img',
to: '../node_modules/@coreui/react/React_Full_Project/img'
} //CoreUI fix */
])
],
module: {
rules: [
rules.jsRule,
rules.scssRule(scssPlugin),
rules.cssFontRule(cssFontPlugin),
rules.fontRule,
rules.htmlRule,
rules.imgRule
]
}
}
module.exports = (env = {}) => {
return merge(commonConfig, env.prod ? prodConfig : devConfig)
}