forked from wesselvanree/shopify-theme-tailwind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
55 lines (50 loc) · 1.44 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
require('dotenv').config()
const path = require('path')
const glob = require('glob')
const removeExtension = file => {
const split = file.split('.')
split.pop()
return split.join('.')
}
const getEntries = () => {
const entries = {}
glob.sync('./src/entries/**/*.{js,jsx,ts,tsx}').forEach(filePath => {
const filename = filePath.replace(/.\/src/).replace(/^.*[\\\/]/, '')
const targetPath = removeExtension(filePath).replace('./src/entries/', '')
let targetFile = removeExtension(filename)
// use parent directory name if filename is index.{js,jsx,ts,tsx} inside child directory
if (
(targetFile == 'index' || targetFile.endsWith('/index')) &&
targetPath != 'index'
) {
const parentFolder = targetPath.split('/index')[0].replace(/(.+\/)+/, '')
targetFile = !!parentFolder ? parentFolder : filename
}
targetFile = targetFile + '.bundle.js'
entries[targetFile] = filePath
})
return entries
}
const mode =
process.env.NODE_ENV === 'production' ? 'production' : 'development'
console.log('Webpack running in ' + mode + ' mode')
module.exports = {
mode: mode,
entry: getEntries(),
output: {
path: path.resolve(__dirname, 'shopify/assets'),
filename: '[name]',
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js'],
},
}