-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
72 lines (67 loc) · 1.95 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
const path = require('path');
const webpackMerge = require('webpack-merge');
const PATHS = {
dist: path.join(__dirname, 'dist'),
index: path.join(__dirname, './src/index.js'),
root: path.join(__dirname, './'),
src: path.join(__dirname, 'src'),
webpackConfig: path.join(__dirname, 'webpack-config'),
};
module.exports = function returnConfig(env) {
const devWebpackConfig = require(`${PATHS.webpackConfig}/webpack.config.dev`)(
PATHS,
);
const prodWebpackConfig = require(`${PATHS.webpackConfig}/webpack.config.prod`)(
PATHS,
);
const webpackAliases = require(`${PATHS.webpackConfig}/webpackAlias`)(PATHS);
const common = webpackMerge([
{
resolve: {
modules: [path.join(__dirname, 'node_modules'), PATHS.src],
alias: webpackAliases,
extensions: ['.js', '.json', '.jsx'],
symlinks: false,
},
module: {
rules: [
{
test: /\.(js)$/,
include: [path.resolve(__dirname, 'src')],
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [
// must be cjs
'@babel/plugin-transform-modules-commonjs',
],
},
},
},
{
test: /\.(png|svg|jpg|gif|ico)$/,
include: [path.join(__dirname, 'src/assets/images')],
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/',
},
},
],
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
},
]);
if (env.environment === 'production') {
return webpackMerge([prodWebpackConfig, common]);
}
return webpackMerge([devWebpackConfig, common]);
};