This repository was archived by the owner on Jun 3, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
90 lines (86 loc) · 2.19 KB
/
Copy pathwebpack.config.js
File metadata and controls
90 lines (86 loc) · 2.19 KB
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
const path = require("path");
const webpack = require("webpack");
const WebpackSprocketsRailsManifestPlugin = require("./manifest-plugin");
const crypto = require("crypto");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const fs = require("fs");
const mode = process.env.RAILS_ENV === 'development' ? 'development' : 'production';
const ref = fs.readFileSync('.git/HEAD').toString().trim();
let commit;
if (ref.startsWith('ref: '))
{
commit = fs.readFileSync(ref.replace('ref: ', '.git/')).toString().trim();
} else {
commit = ref;
}
module.exports = {
devtool: "source-map",
entry: {
application: "./app/javascript/packs/application.ts"
},
mode: mode,
module: {
rules: [
{
test: /\.(ts|tsx)?(\.erb)?$/,
use: [{
loader: 'ts-loader'
}]
},
{
test: /\.s?(css)$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
},
{
test: /\.(jpg|jpeg|png|gif|tiff|ico|svg|eot|otf|ttf|woff|woff2|webm|mp4)$/i,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]'
}
}
]
}
]
},
output: {
filename: mode === "development" ? "[name].js" : "[name]-[contenthash].js",
sourceMapFilename: "[file].map",
path: path.resolve(__dirname, "public/assets"),
},
devServer: {
compress: false,
host: "0.0.0.0",
port: 3000,
},
watchOptions: {
poll: 1000,
},
plugins: [
new webpack.EnvironmentPlugin({
'process.env.SENTRY_RELEASE': `adamjacques-website@${commit.substring(0, 8)}`
}),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
}),
new MiniCssExtractPlugin({
filename: mode === "development" ? "[name].css" : "[name]-[contenthash].css"
}),
new WebpackSprocketsRailsManifestPlugin({
manifestFile: `.sprockets-manifest-${crypto.randomBytes(16).toString("hex")}.json`
})
],
resolve: {
extensions: [".ts", ".js"]
}
}
if (mode === "development") {
module.exports.optimization = {
moduleIds: 'deterministic'
};
} else {
module.exports.optimization = {
usedExports: true
}
}