-
-
Notifications
You must be signed in to change notification settings - Fork 200
Add support to enableTypescriptLoader #50
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
Changes from all commits
fc26e1b
58b7ef7
7e8c118
1352d1c
b43f5c9
846d142
32c2853
a02d8ab
ae1bea3
822ceff
356aaa2
6ec2b52
61370ac
d887a79
23619b2
25b9f18
facc132
f6bc6e7
144acd2
4d5319d
82e17e3
35d9e6f
6d5dee8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import render = require('./render'); | ||
|
||
render(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function render() { | ||
document.getElementById('app').innerHTML = "<h1>Welcome to Your TypeScript App</h1>"; | ||
} | ||
|
||
export = render; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function render() { | ||
document.getElementById('app').innerHTML = "<h1>Welcome to Your TypeScript App</h1>"; | ||
} | ||
|
||
export = render; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"compilerOptions": {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,10 @@ function transform(error) { | |
case 'jsx': | ||
error.loaderName = 'react'; | ||
break; | ||
case 'tsx': | ||
case 'ts': | ||
error.loaderName = 'typescript'; | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch on this! As it looks like you discovered, this is what gives us the good error when you try to load a |
||
// add more as needed | ||
default: | ||
return error; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const loaderFeatures = require('../loader-features'); | ||
const babelLoader = require('./babel'); | ||
|
||
/** | ||
* @param {WebpackConfig} webpackConfig | ||
* @return {Array} of loaders to use for TypeScript | ||
*/ | ||
module.exports = { | ||
getLoaders(webpackConfig) { | ||
loaderFeatures.ensureLoaderPackagesExist('typescript'); | ||
|
||
// some defaults | ||
let config = { | ||
silent: true, | ||
}; | ||
|
||
// allow for ts-loader config to be controlled | ||
webpackConfig.tsConfigurationCallback.apply( | ||
// use config as the this variable | ||
config, | ||
[config] | ||
); | ||
|
||
// use ts alongside with babel | ||
// @see https://github.com/TypeStrong/ts-loader/blob/master/README.md#babel | ||
let loaders = babelLoader.getLoaders(webpackConfig); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. love the note + link 👍 |
||
return loaders.concat([ | ||
{ | ||
loader: 'ts-loader', | ||
// @see https://github.com/TypeStrong/ts-loader/blob/master/README.md#available-options | ||
options: config | ||
} | ||
]); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const WebpackConfig = require('../../lib/WebpackConfig'); | ||
const RuntimeConfig = require('../../lib/config/RuntimeConfig'); | ||
const tsLoader = require('../../lib/loaders/typescript'); | ||
|
||
function createConfig() { | ||
const runtimeConfig = new RuntimeConfig(); | ||
runtimeConfig.context = __dirname; | ||
runtimeConfig.babelRcFileExists = false; | ||
|
||
return new WebpackConfig(runtimeConfig); | ||
} | ||
|
||
describe('loaders/typescript', () => { | ||
it('getLoaders() basic usage', () => { | ||
const config = createConfig(); | ||
config.enableTypeScriptLoader(function(config) { | ||
config.foo = 'bar'; | ||
}); | ||
|
||
const actualLoaders = tsLoader.getLoaders(config); | ||
expect(actualLoaders).to.have.lengthOf(2); | ||
// callback is used | ||
expect(actualLoaders[1].options.foo).to.equal('bar'); | ||
}); | ||
|
||
it('getLoaders() check defaults configuration values', () => { | ||
const config = createConfig(); | ||
config.enableTypeScriptLoader(function(config) { | ||
config.foo = 'bar'; | ||
}); | ||
|
||
const actualLoaders = tsLoader.getLoaders(config); | ||
// callback is used | ||
expect(actualLoaders[1].options.foo).to.equal('bar'); | ||
// defaults | ||
expect(actualLoaders[1].options.silent).to.be.true; | ||
}); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5281,6 +5281,15 @@ tryit@^1.0.1: | |
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb" | ||
|
||
ts-loader@^2.1.0: | ||
version "2.2.0" | ||
resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-2.2.0.tgz#e5fd8f29b967c4fb42abc76396aa8127a1e49924" | ||
dependencies: | ||
colors "^1.0.3" | ||
enhanced-resolve "^3.0.0" | ||
loader-utils "^1.0.2" | ||
semver "^5.0.1" | ||
|
||
[email protected]: | ||
version "0.0.0" | ||
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6" | ||
|
@@ -5324,6 +5333,10 @@ typedarray@^0.0.6: | |
version "0.0.6" | ||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" | ||
|
||
typescript@^2.3.4: | ||
version "2.4.0" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.0.tgz#aef5a8d404beba36ad339abf079ddddfffba86dd" | ||
|
||
uglify-js@^2.8.27: | ||
version "2.8.29" | ||
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about renaming this to
render.tsx
- it would slightly enhance the test, since it would take advantage of the resolve.extensions change and make sure the loader applies to both extensionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good idea! 👍