laravel-mix-typescript-example
laravel-mix-typescript-example copied to clipboard
Example project using TypeScript with Laravel Mix
Laravel Mix TypeScript Example
A minimal example project on how to get started with Laravel Mix and TypeScript.
🔗 Blog post with detailed explanation: https://sebastiandedeyne.com/posts/2017/typescript-with-laravel-mix
Adding TypeScript Support to Laravel Mix
This repository contains the result of a project that supports TypeScript. Here's the recipe for adding support to your own application.
- Install dependencies:
yarn add typescript ts-loader(seepackage.json) - Create a
tsconfig.json, or generate one withnode_modules/.bin/tsc --init(seetsconfig.json) - Add
ts-loaderand register TypeScript file extensions inwebpack.mix.config(see below snippet orwebpack.mix.js) - Set up the
appendTsSuffixTooption if you want to use TypeScript in.vuefiles too (optional)
mix.webpackConfig({
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: { appendTsSuffixTo: [/\.vue$/] },
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['*', '.js', '.jsx', '.vue', '.ts', '.tsx'],
},
});
License
The MIT License (MIT). Please see License File for more information.