-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
104 lines (98 loc) · 2.98 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
import path from 'path'
import webpack from 'webpack'
import TerserPlugin from 'terser-webpack-plugin'
import HoneybadgerSourceMapPlugin from '@honeybadger-io/webpack'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
let mode = 'development'
if (process.env.RAILS_ENV === 'production' || process.env.CI === 'true') {
mode = 'production'
}
export default {
mode,
devtool: 'source-map',
entry: {
application: [
'./app/javascript/application.js',
'./app/assets/stylesheets/application.scss'
]
},
output: {
filename: '[name].js',
sourceMapFilename: '[file].map',
path: path.resolve('app/assets/builds')
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /\/icons\/.*.svg$/,
type: 'asset/source'
},
{
test: /\.(jpg|jpeg|png|gif|tiff|ico|eot|otf|ttf|woff|woff2)$/i,
use: 'asset/resource'
},
{
test: /\.(mjs|cjs|js|jsx)$/,
loader: 'esbuild-loader',
options: {
loader: 'jsx',
target: 'es2021'
},
// ES Module has stricter rules than CommonJS, so file extensions must be
// used in import statements. To ease migration from CommonJS to ESM,
// uncomment the fullySpecified option below to allow Webpack to use a
// looser set of rules. Not recommend for new projects or the long term.
resolve: {
// Allows importing JS files without specifying the file extension.
fullySpecified: false
}
},
{
test: /\.(sa|sc|c)ss$/i,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false
}
},
'postcss-loader'
],
}
]
},
optimization: {
minimize: mode === 'production',
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin()
]
},
plugins: [
// Extract CSS into its own file for the Rails asset pipeline to pick up
new MiniCssExtractPlugin(),
// We're compiling all JS to a single application.js file
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
}),
// Replace ENV variables at build time
new webpack.DefinePlugin({
'process.env.HONEYBADGER_API_KEY': JSON.stringify(process.env.HONEYBADGER_API_KEY),
'process.env.HONEYBADGER_ENV': JSON.stringify(process.env.HONEYBADGER_ENV),
'process.env.RAILS_ENV': JSON.stringify(process.env.RAILS_ENV),
'process.env.SOURCE_VERSION': JSON.stringify(process.env.SOURCE_VERSION)
}),
// Send source maps to HoneyBadger in production for easier debugging
(mode === 'production' && !process.env.CI) && new HoneybadgerSourceMapPlugin({
apiKey: process.env.HONEYBADGER_API_KEY,
assetsUrl: process.env.ASSETS_URL,
revision: process.env.SOURCE_VERSION
})
].filter(Boolean)
}