-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
108 lines (93 loc) · 2.91 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
'use strict';
const webpack = require('webpack');
const path = require('path');
const NODE_ENV = process.env.NODE_ENV || 'development';
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
// process.noDeprecation = true;
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const BasePath = path.resolve(__dirname, 'app');
const config = {
entry:
{
bundle: path.resolve(BasePath, 'src/js/index.js')
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'app/build')
},
// devtool: 'cheap-source-map',
// context: __dirname,
resolve: {
// options for resolving module requests
// (does not apply to resolving to loaders)
modules: [
"node_modules"
// path.resolve(__dirname)
],
// directories where to look for modules
extensions: [".js", ".json", ".jsx", ".css"]
// extensions that are used
},
watch: NODE_ENV === 'development',
watchOptions: {
poll: 1000,
ignored: /node_modules/
},
module: {
// configuration regarding modules
rules: [
// rules for modules (configure loaders, parser options, etc.)
{
test: /\.jsx?$/,
include: [
path.resolve(BasePath, "src/js")
],
exclude: [
path.resolve(__dirname, "node_modules")
],
// Best practices:
// - Use RegExp only in test and for filename matching
// - Use arrays of absolute paths in include and exclude
// - Try to avoid exclude and prefer include
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
},
// options for the loader
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract(
{
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
/*[
// {
// loader: "style-loader" // creates style nodes from JS strings
// },
// {
// loader: "css-loader" // translates CSS into CommonJS
// },
// {
// loader: "sass-loader" // compiles Sass to CSS
// }
]*/
}
]
},
plugins: [
new ExtractTextPlugin('style.css')
]
};
module.exports = (env, argv) => {
if (argv.mode === 'development') {
config.devtool = 'source-map';
}
if (argv.mode === 'production') {
//...
}
return config;
};