-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
83 lines (73 loc) · 1.87 KB
/
webpack.config.js
File metadata and controls
83 lines (73 loc) · 1.87 KB
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
const webpack = require('webpack');
const path = require('path');
const HtmlWebPackPlugin = require("html-webpack-plugin");
const ROOT_PATH = path.resolve(__dirname);
const env = process.env.WEBPACK_ENV || 'dev';
const appName = 'app';
const host = '0.0.0.0';
const port = '8000';
const plugins = [];
let outputFile;
if (env === 'build') {
outputFile = `${appName}.min.js`;
} else {
outputFile = `${appName}.js`;
}
console.log('outputFile === ' + outputFile);
console.log(`full path === ${__dirname}/lib`);
const dev = env === 'dev';
plugins.push(new HtmlWebPackPlugin({
template: "./public/index.html",
filename: "./index.html"
}));
const config = {
mode: dev ? 'development' : 'production',
entry: './src/index.js',
devtool: 'source-map',
output: {
path: path.join(__dirname, 'lib'),
filename: outputFile,
publicPath: '/public/'
},
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
loader: 'babel-loader',
exclude: /(node_modules|bower_components)/,
query: {
presets: ['@babel/preset-env', '@babel/preset-react']
}
},
{
test: /\.(png|jpg|gif)$/,
loader: 'url-loader?limit=20000',
include: path.resolve(ROOT_PATH, 'src/assets/img')
},
{
test: /\.scss$/,
loaders: ['style', 'css', 'sass']
},
]
},
resolve: {
modules: [path.resolve('./src'), 'node_modules'],
extensions: ['.js', '.jsx'],
alias: {
assets: path.resolve('./src/assets'),
components: path.resolve('./src/components'),
styles: path.resolve('./src/styles'),
services: path.resolve('./src/services'),
react: path.resolve(__dirname, 'node_modules', 'react')
}
},
plugins: plugins
};
if (dev) {
config.devServer = {
contentBase: path.join(__dirname, 'lib'),
compress: false,
port: port
};
}
module.exports = config;