Skip to content

Commit 250fc15

Browse files
Add typescript typings (laravel-mix#2493)
Co-authored-by: Jordan Pittman <[email protected]> Co-authored-by: Geoff Garbers <[email protected]>
1 parent 29a5d4a commit 250fc15

File tree

2 files changed

+226
-0
lines changed

2 files changed

+226
-0
lines changed

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "6.0.0-beta.2",
44
"description": "Laravel Mix is an elegant wrapper around Webpack for the 80% use case.",
55
"main": "src/index.js",
6+
"types": "typings/index.d.ts",
67
"scripts": {
78
"mix": "./bin/cli.js",
89
"test": "ava --verbose --serial",
@@ -46,6 +47,18 @@
4647
"@babel/plugin-syntax-dynamic-import": "^7.8.0",
4748
"@babel/plugin-transform-runtime": "^7.11.5",
4849
"@babel/preset-env": "^7.11.5",
50+
"@babel/runtime": "^7.2.0",
51+
"@types/autoprefixer": "^9.6.1",
52+
"@types/babel-core": "^6.25.6",
53+
"@types/browser-sync": "^2.26.1",
54+
"@types/clean-css": "^4.2.1",
55+
"@types/cssnano": "^4.0.0",
56+
"@types/imagemin-gifsicle": "^5.2.0",
57+
"@types/imagemin-mozjpeg": "^8.0.0",
58+
"@types/imagemin-optipng": "^5.2.0",
59+
"@types/imagemin-svgo": "^7.0.0",
60+
"@types/purifycss-webpack": "^0.7.0",
61+
"autoprefixer": "^9.4.2",
4962
"@babel/runtime": "^7.9.0",
5063
"autoprefixer": "^10.0.1",
5164
"babel-loader": "^8.0.4",

typings/index.d.ts

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
// Type definitions for laravel-mix 6.0
2+
// Project: https://github.com/JeffreyWay/laravel-mix#readme
3+
// Definitions by: Geoff Garbers <https://github.com/garbetjie>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
import * as webpack from 'webpack';
7+
import { Options as AutoprefixerConfig } from 'autoprefixer';
8+
import { Options as CleanCssConfig } from 'clean-css';
9+
import { CssNanoOptions as CssNanoConfig } from 'cssnano';
10+
import { Options as GifsicleConfig } from 'imagemin-gifsicle';
11+
import { Options as MozjpegConfig } from 'imagemin-mozjpeg';
12+
import { Options as OptipngConfig } from 'imagemin-optipng';
13+
import { Options as SvgoConfig } from 'imagemin-svgo';
14+
import { TransformOptions as BabelConfig } from 'babel-core';
15+
import { Options as BrowserSyncConfig } from 'browser-sync';
16+
import { TerserPluginOptions } from 'terser-webpack-plugin';
17+
18+
interface MixConfig {
19+
production?: boolean;
20+
hmr?: boolean;
21+
hmrOptions?: {
22+
host: string;
23+
port: string;
24+
};
25+
postCss?: any[];
26+
autoprefixer?: {
27+
enabled?: boolean;
28+
options?: AutoprefixerConfig;
29+
};
30+
publicPath?: string;
31+
notifications?: {
32+
onSuccess?: boolean;
33+
onFailure?: boolean;
34+
};
35+
sourceMaps?: boolean;
36+
resourceRoot?: string;
37+
imgLoaderOptions?: {
38+
enabled?: boolean;
39+
gifsicle?: GifsicleConfig;
40+
mozjpeg?: MozjpegConfig;
41+
optipng?: OptipngConfig;
42+
svgo?: SvgoConfig;
43+
};
44+
fileLoaderDirs?: {
45+
images?: string;
46+
fonts?: string;
47+
};
48+
babel?: (babelRcPath: string) => BabelConfig;
49+
processCssUrls?: boolean;
50+
terser?: TerserPluginOptions;
51+
cssNano?: CssNanoConfig;
52+
cleanCss?: CleanCssConfig;
53+
webpackConfig?: webpack.Configuration;
54+
babelConfig?: BabelConfig;
55+
clearConsole?: boolean;
56+
merge?: (options: MixConfig) => void;
57+
}
58+
59+
declare module 'laravel-mix' {
60+
export = Api;
61+
62+
namespace builder {
63+
interface Entry {}
64+
}
65+
66+
namespace components {
67+
type Autoload = (libs: Record<string, string>) => Api;
68+
type BrowserSync = (userConfig: string | BrowserSyncConfig) => Api;
69+
type DisableNotifications = () => Api;
70+
type DisableSuccessNotifications = DisableNotifications;
71+
type Dump = DumpWebpackConfig;
72+
type DumpWebpackConfig = () => Api;
73+
type Extend = (
74+
name: string,
75+
component:
76+
| Component
77+
| ((
78+
mix: Api,
79+
config: webpack.Configuration,
80+
...args: any[]
81+
) => void)
82+
) => Api;
83+
type Extract =
84+
| (() => Api)
85+
| ((output: string) => Api)
86+
| ((libs: string | string[], output: string) => Api);
87+
type Notifications = () => Api;
88+
type Version = (files?: string | string[]) => Api;
89+
90+
// CSS-related
91+
type _Preprocessor = (
92+
src: string,
93+
output: string,
94+
pluginOptions?: object,
95+
postCssPlugins?: any[]
96+
) => Api;
97+
type Css = () => Api;
98+
type Stylus = _Preprocessor;
99+
type Less = _Preprocessor;
100+
type Sass = _Preprocessor;
101+
type PostCss = (src: string, output: string, plugins?: any[]) => Api;
102+
103+
// JS-related
104+
type Coffee = Javascript;
105+
type Javascript = (entry: string | string[], output: string) => Api;
106+
type Typescript = Javascript;
107+
108+
// File-related
109+
type Combine = (
110+
src: string | string[],
111+
output?: string,
112+
babel?: boolean
113+
) => Api;
114+
type Babel = Combine;
115+
type Minify = Combine;
116+
type Scripts = Combine;
117+
type Styles = Combine;
118+
119+
type Copy = (from: string | string[], to: string) => Api;
120+
type CopyDirectory = Copy;
121+
122+
// Features
123+
type Preact = () => Api;
124+
type React = () => Api;
125+
type Vue = (
126+
options: {
127+
version: number;
128+
extractStyles?: boolean;
129+
globalStyles?:
130+
| boolean
131+
| string
132+
| string[]
133+
| Record<string, string | string[]>;
134+
}
135+
) => Api;
136+
}
137+
138+
interface Component {
139+
name?: () => string;
140+
register?: (...args: any[]) => void;
141+
passive?: boolean;
142+
mix?: () => string[];
143+
dependencies?: () => string | string[];
144+
boot?: () => void;
145+
babelConfig?: () => BabelConfig;
146+
webpackPlugins?: () => webpack.WebpackPluginInstance[];
147+
webpackConfig?: (config: webpack.Configuration) => void;
148+
webpackEntry?: (entry: builder.Entry) => void;
149+
webpackRules?: () => webpack.RuleSetRule | webpack.RuleSetRule[];
150+
}
151+
152+
class Api {
153+
sourceMaps(
154+
generateForProduction?: boolean,
155+
devType?: string,
156+
productionTyp?: string
157+
): Api;
158+
159+
setPublicPath(defaultPath: string): Api;
160+
161+
setResourceRoot(path: string): Api;
162+
163+
webpackConfig(
164+
config:
165+
| webpack.Configuration
166+
| ((webpack: typeof import('webpack')) => webpack.Configuration)
167+
): Api;
168+
169+
babelConfig(config: BabelConfig): Api;
170+
171+
options(options: MixConfig): Api;
172+
173+
then(callback: (data: any) => void): Api;
174+
175+
override(callback: (data: any) => void): Api;
176+
177+
inProduction(): boolean;
178+
179+
config: MixConfig;
180+
181+
// Components.
182+
183+
autoload: components.Autoload;
184+
browserSync: components.BrowserSync;
185+
coffee: components.Coffee;
186+
combine: components.Combine;
187+
scripts: components.Scripts;
188+
babel: components.Babel;
189+
styles: components.Styles;
190+
minify: components.Minify;
191+
copy: components.Copy;
192+
copyDirectory: components.CopyDirectory;
193+
css: components.Css; // TODO
194+
disableNotifications: components.DisableNotifications;
195+
disableSuccessNotifications: components.DisableSuccessNotifications;
196+
dumpWebpackConfig: components.DumpWebpackConfig;
197+
dump: components.Dump;
198+
extend: components.Extend;
199+
extract: components.Extract;
200+
js: components.Javascript;
201+
less: components.Less;
202+
notifications: components.Notifications;
203+
postCss: components.PostCss;
204+
preact: components.Preact;
205+
react: components.React;
206+
sass: components.Sass;
207+
stylus: components.Stylus;
208+
typeScript: components.Typescript;
209+
ts: components.Typescript;
210+
version: components.Version;
211+
vue: components.Vue;
212+
}
213+
}

0 commit comments

Comments
 (0)