Skip to content

Commit

Permalink
Pass options to ts-loader using a third argument (#2287)
Browse files Browse the repository at this point in the history
* Pass options to ts-loader using a third argument

* change spread operator to Object.assign()
  • Loading branch information
jpmaga authored and JeffreyWay committed Dec 17, 2019
1 parent ab97c17 commit 46afaa2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
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
);
});

0 comments on commit 46afaa2

Please sign in to comment.