-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
98 lines (86 loc) · 2.46 KB
/
start.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
var fs = require("fs")
const {
browserify,
sucrasify,
createDevServer,
HotReloadPlugin,
tinyify,
envify,
aliasify,
getFileSize
} = require("./tools/omnify")
const serve = () => {
var bundler = browserify("src/index.tsx", {
cache: {},
packageCache: {},
debug: false,
sourceMaps: false,
extensions: [".ts", ".tsx", ".js", ".jsx"],
plugin: [HotReloadPlugin],
transform: [
[sucrasify.configure({ hot: true })],
//[envify({ NODE_ENV: "production" }), { global: true }],
[
aliasify.configure({
aliases: {
"react": "react/cjs/react.production.min.js",
"react-dom": "react-dom/cjs/react-dom.production.min.js",
"scheduler": "scheduler/cjs/scheduler.production.min.js",
"react-reconciler": "react-reconciler/cjs/react-reconciler.production.min.js"
},
appliesTo: { includeExtensions: [".js", ".jsx", ".tsx", ".ts"] }
}),
{ global: true }
]
]
})
createDevServer({
browserify_instance: bundler,
static_url: "main.js"
})
}
const bundle = () => {
fs.mkdirSync("public", { recursive: true })
//var shakeify = require("common-shakeify")
//var packflat = require("browser-pack-flat/plugin")
console.time("OMNIFY:BUNDLETIME")
var bundler = browserify("src/index.tsx", {
cache: {},
packageCache: {},
debug: false,
sourceMaps: false,
extensions: [".ts", ".tsx", ".js", ".jsx"],
plugin: [
//tinyify,
//shakeify
],
transform: [
sucrasify,
//[envify({ NODE_ENV: "production" }), { global: true }],
// [
// aliasify.configure({
// aliases: {
// "react": "react/cjs/react.production.min.js",
// "react-dom": "react-dom/cjs/react-dom.production.min.js",
// "scheduler": "scheduler/cjs/scheduler.production.min.js",
// "react-reconciler": "react-reconciler/cjs/react-reconciler.production.min.js"
// },
// appliesTo: { includeExtensions: [".js", ".jsx", ".tsx", ".ts"] }
// }),
// { global: true }
// ]
]
})
bundler
.bundle()
.pipe(fs.createWriteStream("public/app.js"))
.on("close", () => {
console.timeEnd("OMNIFY:BUNDLETIME")
console.log(getFileSize("public/app.js"))
})
}
const args = process.argv.slice(2)
args.includes("--serve") && serve()
args.includes("--bundle") && bundle()
//default
args[0] == null && serve()