-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamer-config.js
32 lines (26 loc) · 932 Bytes
/
namer-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
const fs = require("fs");
const path = require("path");
// Path to package.json
const packagePath = path.resolve(__dirname, "package.json");
// Read package.json
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
// Check exists "parcel-namer-rewrite"
if (!packageJson["parcel-namer-rewrite"]) {
packageJson["parcel-namer-rewrite"] = {};
}
// Set rules based on NODE_ENV
const env = process.env.NODE_ENV || "development";
packageJson["parcel-namer-rewrite"].rules =
env === "production"
? {
"(.*).css": "{hash}.css",
"(.*).js": "{hash}.js",
}
: {
"(.*).css": "dev_$1.{hash}.css",
"(.*).js": "dev_$1.{hash}.js",
};
packageJson["parcel-namer-rewrite"].silent = env === "development";
// Write changes back to package.json
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
console.log(`Updated parcel-namer-rewrite rules for ${env}`);