Skip to content

Commit dda8469

Browse files
committed
build: simplify minifying script
1 parent 52d04ff commit dda8469

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

build.config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { defineBuildConfig } from 'unbuild'
22

33
export default defineBuildConfig({
4-
// TODO: fix issue in unbuild with inlining package.json
5-
// `Inlined implicit external D:\a\color-mode\color-mode\package.json`
6-
failOnWarn: false,
7-
entries: ['src/script'],
84
hooks: {
95
'rollup:options' (_ctx, options) {
106
options.treeshake = false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"dist"
2828
],
2929
"scripts": {
30-
"prepack": "nuxt-module-build build && esbuild --minify dist/script.mjs --outfile=dist/script.min.js",
30+
"prepack": "nuxt-module-build build && esbuild --minify src/script.js --outfile=dist/script.min.js",
3131
"build": "pnpm run prepack",
3232
"dev": "nuxi dev playground",
3333
"dev:build": "nuxi build playground",

src/script.ts renamed to src/script.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-check
2+
13
// Add dark / light detection that runs before loading Nuxt
24
(() => {
35
// Global variable minimizers
@@ -16,7 +18,7 @@
1618

1719
addColorScheme(value)
1820

19-
// @ts-ignore
21+
2022
w['<%= options.globalName %>'] = {
2123
preference,
2224
value,
@@ -25,7 +27,7 @@
2527
removeColorScheme
2628
}
2729

28-
// @ts-ignore
30+
/** @param {string} value */
2931
function addColorScheme (value) {
3032
const className = '<%= options.classPrefix %>' + value + '<%= options.classSuffix %>'
3133
const dataValue = '<%= options.dataValue %>'
@@ -39,7 +41,7 @@
3941
}
4042
}
4143

42-
// @ts-ignore
44+
/** @param {string} value */
4345
function removeColorScheme (value) {
4446
const className = '<%= options.classPrefix %>' + value + '<%= options.classSuffix %>'
4547
const dataValue = '<%= options.dataValue %>'
@@ -53,14 +55,16 @@
5355
}
5456
}
5557

56-
// @ts-ignore
58+
/** @param {string} suffix */
5759
function prefersColorScheme (suffix) {
5860
return w.matchMedia('(prefers-color-scheme' + suffix + ')')
5961
}
6062

6163
function getColorScheme () {
62-
// @ts-ignore
63-
if (w.matchMedia && prefersColorScheme('').media !== 'not all') {
64+
if (
65+
// @ts-expect-error TS assumes matchMedia is always defined
66+
w.matchMedia
67+
&& prefersColorScheme('').media !== 'not all') {
6468
for (const colorScheme of knownColorSchemes) {
6569
if (prefersColorScheme(':' + colorScheme).matches) {
6670
return colorScheme

src/script.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
script.ts
1+
script.js

0 commit comments

Comments
 (0)