Skip to content

Commit 5b3aff1

Browse files
committed
Export TS declaration files
- Swap out awesome-typescript-loader with ts-loader due to a bug in AT that prevents generation of TS declaration files for interfaces - Stitch together the generated TS declaration files - Remove the temporary folder once generated
1 parent 565df59 commit 5b3aff1

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"awesome-typescript-loader": "^3.1.3",
2424
"cross-env": "^5.0.0",
2525
"css-loader": "^0.28.1",
26+
"dts-bundle": "^0.7.2",
2627
"enzyme": "^2.8.2",
2728
"es6-promise": "^4.1.0",
2829
"extract-text-webpack-plugin": "^2.1.0",
@@ -54,6 +55,7 @@
5455
"sass-loader": "^6.0.5",
5556
"sinon": "^2.2.0",
5657
"style-loader": "^0.17.0",
58+
"ts-loader": "^2.0.3",
5759
"tslint": "^5.2.0",
5860
"typescript": "^2.3.2",
5961
"url-loader": "^0.5.8",
@@ -67,7 +69,7 @@
6769
"test": "cross-env NODE_ENV=test karma start",
6870
"clean": "rimraf dist",
6971
"start": "webpack-dev-server --debug --output-pathinfo --history-api-fallback --hot --inline --progress --colors --port 3000 --open",
70-
"build": "rimraf dist && cross-env NODE_ENV=production webpack --progress --colors && cross-env NODE_ENV=minify webpack --progress --colors",
72+
"build": "rimraf dist && cross-env NODE_ENV=production webpack --progress --colors && cross-env NODE_ENV=minify webpack --progress --colors && rimraf dist/types",
7173
"analyze": "cross-env NODE_ENV=analyze webpack --progress --colors"
7274
}
7375
}

Diff for: tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"target": "es5",
55
"lib": ["es5", "dom"],
66
"sourceMap": true,
7-
"allowJs": true,
87
"jsx": "react",
98
"experimentalDecorators": true,
109
"allowSyntheticDefaultImports": true,
@@ -15,7 +14,9 @@
1514
"noImplicitAny": false,
1615
"strictNullChecks": true,
1716
"suppressImplicitAnyIndexErrors": true,
18-
"noUnusedLocals": true
17+
"noUnusedLocals": true,
18+
"declaration": true,
19+
"declarationDir": "types"
1920
},
2021
"exclude": [
2122
"node_modules",

Diff for: webpack.config.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const base = {
4141
// .ts, .tsx
4242
{
4343
test: /\.tsx?$/,
44-
use: IS_PROD ? 'awesome-typescript-loader' : ['react-hot-loader', 'awesome-typescript-loader']
44+
use: IS_PROD ? 'ts-loader' : ['react-hot-loader', 'ts-loader']
4545
},
4646
{
4747
test: /\.css/,
@@ -119,6 +119,22 @@ const base = {
119119
}
120120
};
121121

122+
function DtsBundlePlugin() {}
123+
124+
DtsBundlePlugin.prototype.apply = function (compiler) {
125+
compiler.plugin('done', function () {
126+
const dts = require('dts-bundle');
127+
128+
dts.bundle({
129+
name: 'onenotepicker',
130+
main: path.resolve(__dirname) + '/dist/types/src/oneNotePicker.d.ts',
131+
out: path.resolve(__dirname) + '/dist/oneNotePicker.d.ts',
132+
removeSource: true,
133+
outputAsModuleFolder: true
134+
});
135+
});
136+
};
137+
122138
const prod = {
123139
devtool: 'source-map',
124140
plugins: [
@@ -130,7 +146,8 @@ const prod = {
130146
'process.env': {
131147
'NODE_ENV': JSON.stringify('production')
132148
}
133-
})
149+
}),
150+
new DtsBundlePlugin()
134151
],
135152
externals: {
136153
'react': 'React',
@@ -173,3 +190,4 @@ if (IS_ANALYZE) {
173190
}
174191

175192
module.exports = webpackConfiguration;
193+

0 commit comments

Comments
 (0)