Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass options to ts-loader using a third argument #2287

Merged
merged 2 commits into from Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/components/TypeScript.js
@@ -1,13 +1,30 @@
let JavaScript = require('./JavaScript');

class TypeScript extends JavaScript {
constructor() {
super();
this.options = {};
}

/**
* The API name for the component.
*/
name() {
return ['typeScript', 'ts'];
}

/**
* Register the component.
*
* @param {*} entry
* @param {string} output
* @param {object} options
*/
register(entry, output, options = {}) {
super.register(entry, output);
this.options = options;
}

/**
* Required dependencies for the component.
*/
Expand All @@ -23,9 +40,11 @@ class TypeScript extends JavaScript {
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
appendTsSuffixTo: [/\.vue$/]
}
options: Object.assign(
{},
{ appendTsSuffixTo: [/\.vue$/] },
this.options
)
});
}

Expand Down
9 changes: 9 additions & 0 deletions test/features/typescript.js
Expand Up @@ -45,3 +45,12 @@ test.serial('it applies the correct webpack rules', t => {
)
);
});

test.serial('it is able to apply options to ts-loader', t => {
mix.ts('resources/assets/js/app.js', 'public/js', { transpileOnly: true });

t.truthy(
buildConfig().module.rules.find(rule => rule.loader === 'ts-loader')
.options.transpileOnly
);
});