-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
executable file
·120 lines (115 loc) · 2.66 KB
/
webpack.config.babel.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
import path from 'path'
import { fileURLToPath } from 'url'
import ProgressBarPlugin from 'progress-bar-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import BrowserSyncPlugin from 'browser-sync-webpack-plugin'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const isProduction =
process.argv[process.argv.indexOf('--mode') + 1] === 'production'
const CSSLoader = {
loader: 'css-loader',
options: {
modules: 'global',
importLoaders: 2,
camelCase: true,
sourceMap: false, // turned off as causes delay
},
}
function webpackConfig() {
return {
mode: isProduction ? 'production' : 'development',
cache: isProduction ? false : true,
watch: isProduction ? false : true,
devtool: isProduction ? false : 'eval',
entry: {
app: ['./assets/js/app.jsx', './assets/css/app.scss'],
account: ['./assets/js/account/index.js'],
checkout: ['./assets/js/checkout/index.js'],
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
clean: true,
},
externals: {
jQuery: 'jQuery',
react: 'React',
'react-dom': 'ReactDOM',
},
resolve: {
extensions: ['.js', '.jsx'],
// import 'tippy.js/themes/light.css'
// import 'tippy.js/dist/tippy.css'
// alias: {
// 'tippy.js': path.resolve(__dirname, './node_modules/tippy.js'),
// },
},
plugins: [
!isProduction &&
new BrowserSyncPlugin(
{
proxy: 'v8.loc',
host: 'localhost',
port: 9000,
https: {
key: '/Users/andrew/_ssl/localhost-v8.key',
cert: '/Users/andrew/_ssl/localhost-v8.crt',
},
files: [
'**/*.php',
'**/*.css',
{
match: '**/*.js',
options: {
ignored: 'dist/**/*.js', //the js output folder
},
},
],
reloadDelay: 0,
},
{ injectCss: true }
),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new ProgressBarPlugin({
format: ' build [:bar] ' + ':percent' + ' (:elapsed seconds)',
clear: false,
}),
],
module: {
rules: [
{
test: /\.svg/,
type: 'asset/inline',
},
{
test: /\.s[ac]ss$/i,
exclude: /node_modules/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
},
],
},
{
test: /\.(js|jsx)/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { targets: 'defaults' }]],
},
},
},
],
},
}
}
const finalConfig = webpackConfig()
export default finalConfig