-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.cjs
76 lines (73 loc) · 2.47 KB
/
webpack.config.cjs
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
/**
* This is a main entrypoint for Webpack config.
*
* @since 1.0.0
*/
const path = require('path')
// Paths to find our files and provide BrowserSync functionality.
const projectPaths = {
projectDir: __dirname, // Current project directory absolute path.
projectJsPath: path.resolve(__dirname, './src'),
projectOutput: path.resolve(__dirname, './public'),
projectWebpack: path.resolve(__dirname, 'webpack'),
}
// Files to bundle
const projectFiles = {
// JS configurations for development and production
projectJs: {
eslint: false, // enable or disable eslint | this is only enabled in development env.
filename: `[name]${`${Math.random()}`.substring(3, 10)}.js`,
entry: {
index: projectPaths.projectJsPath + '/main.jsx',
},
rules: {
test: /\.(js|jsx)$/,
},
},
// Source Maps configurations
projectSourceMaps: {
// Sourcemaps are nice for debugging but takes lots of time to compile,
// so we disable this by default and can be enabled when necessary
enable: false,
env: 'dev', // dev | dev-prod | prod
// ^ Enabled only for development on default, use "prod" to enable only for production
// or "dev-prod" to enable it for both production and development
devtool: 'source-map', // type of sourcemap, see more info here: https://webpack.js.org/configuration/devtool/
// ^ If "source-map" is too slow, then use "cheap-source-map" which struck a good balance between build performance and debuggability.
},
// Images configurations for development and production
projectImages: {
rules: {
test: /\.(ttf|eot|svg|png|gif)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
},
// Optimization settings
minimizerOptions: {
// Lossless optimization with custom option
// Feel free to experiment with options for better result for you
// More info here: https://webpack.js.org/plugins/image-minimizer-webpack-plugin/
plugins: [
[
'svgo',
{
plugins: [{ removeViewBox: false }],
},
],
],
},
},
}
// Merging the projectFiles & projectPaths objects
const projectOptions = {
...projectPaths,
...projectFiles,
projectConfig: {},
}
// Get the development or production setup based
// on the script from package.json
module.exports = (env) => {
if (env.NODE_ENV === 'production') {
return require('./webpack/config.production.cjs')(projectOptions)
} else {
return require('./webpack/config.development.cjs')(projectOptions)
}
}