-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
123 lines (119 loc) · 2.8 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
const webpack = require('webpack')
const { merge } = require('webpack-merge')
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const baseConfig = {
entry: {
base: [
'./isimip_data/core/assets/scss/base.scss',
'./isimip_data/core/assets/js/base.js',
],
download: [
'./isimip_data/download/assets/scss/download.scss',
'./isimip_data/download/assets/js/download.js',
],
metadata: [
'./isimip_data/metadata/assets/scss/metadata.scss',
'./isimip_data/metadata/assets/js/metadata.js',
],
resources: [
'./isimip_data/metadata/assets/scss/resources.scss',
'./isimip_data/metadata/assets/js/resources.js',
],
search: [
'./isimip_data/search/assets/scss/search.scss',
'./isimip_data/search/assets/js/search.js',
]
},
resolve: {
alias: {
isimip_data: path.resolve(__dirname, './isimip_data/')
},
extensions: ['*', '.js', '.jsx']
},
output: {
libraryTarget: 'this',
library: '[name]',
path: path.resolve('./static/'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
options: { presets: ["@babel/env"] }
},
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
},
{
test: /\.(woff2?|ttf|eot|otf)$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]'
}
},
{
test: /\.(svg|png|jpg)$/,
loader: 'file-loader',
options: {
name: 'images/[name].[ext]'
}
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
new CopyWebpackPlugin({
patterns: [
{
from: '**/*',
to: './/images/',
context: './isimip_data/core/assets/images/'
}
]
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
]
}
const developmentConfig = {
devtool: 'eval',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
]
}
const productionConfig = {
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
],
optimization: {
minimize: true,
minimizer: [new TerserPlugin()]
}
}
module.exports = (env, argv) => {
if (argv.mode === 'development') {
return merge(baseConfig, developmentConfig)
} else {
return merge(baseConfig, productionConfig)
}
}