Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Added ts-loader example #167

Merged
merged 1 commit into from
Jun 2, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ function tslint_loader {
) | egrep -i "forbidden .?var.? keyword"
}

function ts_loader--webpack2 {
echo "Testing HappyPack with ts-loader (webpack 2)"
echo "-----------------------------------------------"

setup_example "examples/ts-loader--webpack2"

(
cd examples/ts-loader--webpack2;
./node_modules/.bin/webpack --bail &&
./node_modules/.bin/webpack --bail --config webpack.config--raw.js &&
diff dist/main.js dist--raw/main.js &&
grep "success" dist/main.js
)
}

function transform_loader {
echo "Testing HappyPack with transform-loader (coffeeify & brfs)"
echo "----------------------------------------------------------"
Expand Down Expand Up @@ -179,5 +194,6 @@ run_task tslint_loader
run_task transform_loader
run_task webpack2
run_task webpack2-extract-text
run_task ts_loader--webpack2
run_task source_maps
run_task json_loader
14 changes: 14 additions & 0 deletions examples/ts-loader--webpack2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "happypack-examples__ts-loader",
"version": "1.0.0",
"description": "",
"main": "index.js",
"author": "John Reilly <[email protected]> ",
"license": "ISC",
"devDependencies": {
"fork-ts-checker-webpack-plugin": "^0.1.2",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, change it to ^2.0.0 :)

"ts-loader": "^2.0.3",
"typescript": "^2.2.2",
"webpack": "^2.2.0"
}
}
6 changes: 6 additions & 0 deletions examples/ts-loader--webpack2/src/fileWithoutError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

const x: number = 1;

console.log('success');

export = x;
4 changes: 4 additions & 0 deletions examples/ts-loader--webpack2/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

import * as x1 from './fileWithoutError';

export = x1 + 2;
4 changes: 4 additions & 0 deletions examples/ts-loader--webpack2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"compilerOptions": {
}
}
35 changes: 35 additions & 0 deletions examples/ts-loader--webpack2/webpack.config--raw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

var process = require('process');
var path = require('path');
var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

module.exports = {
context: __dirname, // to automatically find tsconfig.json
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].raw.js'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be:

        path: path.resolve(__dirname, 'dist--raw'),
        filename: '[name].js'

:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooh you might be right!

},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader',
options: { transpileOnly: true }
}
]
},
resolve: {
extensions: ['.ts', '.tsx', 'js']
},
plugins: [
new ForkTsCheckerWebpackPlugin({
tslint: false, // disable tslint support

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unnecessary now - it's disabled by default

watch: './src', // optional but improves performance (less stat calls)
workers: ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE, // use multi-process mode, leave 2 cpu's free for builder and system
blockEmit: process.env.NODE_ENV === 'production' // for production make it synchronous

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, remove this - this is no longer useful - it's computed automatically

})
]
};
45 changes: 45 additions & 0 deletions examples/ts-loader--webpack2/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

var process = require('process');
var path = require('path');
var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
var HappyPack = require('../../');

module.exports = {
context: __dirname, // to automatically find tsconfig.json
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: path.resolve(__dirname, '../../loader?id=ts')
}
]
},
resolve: {
extensions: ['.ts', '.tsx', 'js']
},
plugins: [
new HappyPack({
id: 'ts',
threads: 2,
loaders: [
{
path: 'ts-loader',
query: { happyPackMode: true }
}
]
}),
new ForkTsCheckerWebpackPlugin({
tslint: false, // disable tslint support
watch: './src', // optional but improves performance (less stat calls)
workers: ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE, // use multi-process mode, leave 2 cpu's free for builder and system
blockEmit: process.env.NODE_ENV === 'production' // for production make it synchronous
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above - tslint and blockEmit is no longer needed :)

]
};