-
-
Notifications
You must be signed in to change notification settings - Fork 372
Add support for typescript #11
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
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,11 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "noEmitHelpers": true, | ||
| "module": "es2015", | ||
| "moduleResolution": "node", | ||
| "target": "es2017", | ||
|
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. Should this be set to
Member
Author
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. Nah, the ts should compile the latest js version possible because babel is applied right after that anyways. |
||
| "noImplicitAny": false, | ||
| "sourceMap": true, | ||
| "jsx": "preserve" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,9 @@ export default (env) => { | |
| let babelrc = readJson(resolve(cwd, '.babelrc')) || {}; | ||
| let browsers = env.pkg.browserslist || ['> 1%', 'last 2 versions', 'IE >= 9']; | ||
|
|
||
| // use user specified tsconfig.json if present | ||
| let tsconfig = resolve(cwd, 'tsconfig.json'); | ||
|
|
||
| return group([ | ||
| setContext(src('.')), | ||
| customConfig({ | ||
|
|
@@ -97,6 +100,37 @@ export default (env) => { | |
| } | ||
| }), | ||
|
|
||
| // TypeScript | ||
| customConfig({ | ||
| module: { | ||
| loaders: [ | ||
| { | ||
| enforce: 'pre', | ||
| test: /\.tsx?$/, | ||
| use: [ | ||
| { | ||
| loader: resolve(__dirname, './npm-install-loader'), | ||
| options: { | ||
| modules: ['typescript', 'awesome-typescript-loader'], | ||
| save: true | ||
| } | ||
| }, | ||
| { | ||
| loader: 'awesome-typescript-loader', | ||
| options: { | ||
| sourceMap: true, | ||
| useBabel: true, | ||
| babelOptions: createBabelConfig(env), | ||
| useCache: true, | ||
| configFileName: tsconfig, | ||
|
Member
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. I wonder if 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. As a side-note, it's working fine for me with export default function (config, env, helpers) {
config.module.loaders.push({
enforce: "pre",
test: /\.tsx?$/,
loader: "ts-loader"
});
}
Member
Author
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. @wub How is your experience so far with @developit I'm honestly thinking of closing this PR as now the ability to extend the webpack config has been added. That way the core cli remains lean and a config like @wub posted above is as easy as it gets.
Collaborator
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. @developit @marvinhagemeister should I add above to the 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. It would be great to have some example how to setup preact-cli to work with TypeScript with css modules
Member
Author
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. @rkostrzewski yep. @porfirioribeiro CSS-Modules should work out of the box. The only difference is that you'll have to revert to // styles appears as type any, because ts has no idea of `.css` files
const styles = require("foo.css");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. @marvinhagemeister |
||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| }), | ||
|
|
||
| // LESS, SASS & CSS | ||
| customConfig({ | ||
| module: { | ||
|
|
||
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.
Since
noEmitHelpersis set to true, can we also addtslibas dependency?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.
Since babel is applied right after the ts step and brings its own set helpers, I don't think adding the weight of another helper library is beneficial.