Skip to content

Commit 2a2e988

Browse files
committed
typescript solution implemented
1 parent 0c34358 commit 2a2e988

26 files changed

+425
-17831
lines changed

.vscode/tasks.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "dev",
9+
"problemMatcher": []
10+
},
11+
{
12+
"type": "npm",
13+
"script": "test:watch",
14+
"problemMatcher": []
15+
},
16+
{
17+
"type": "npm",
18+
"script": "build",
19+
"problemMatcher": []
20+
}
21+
]
22+
}

.webpack/webpack.config.base.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1-
// TODO: extract to this module all basic logic used by all configurations
1+
// this module has all basic logic used by all configurations
2+
const webpack = require('webpack');
3+
const _ = require('lodash');
4+
const path = require('path');
5+
6+
/**
7+
*
8+
* @param {webpack.Configuration} mergeWith
9+
* @returns {webpack.Configuration}
10+
*/
11+
function createConfiguration(mergeWith = undefined) {
12+
/**
13+
* @type {webpack.Configuration}
14+
*/
15+
let res = {
16+
module: {
17+
rules: [{
18+
test: /(\.tsx|\.ts)$/,
19+
loaders: ['babel-loader', 'ts-loader'],
20+
exclude: /(node_modules|bower_components)/
21+
},
22+
{
23+
test: /(\.jsx|\.js)$/,
24+
loader: 'babel-loader',
25+
exclude: /(node_modules|bower_components)/
26+
},
27+
{
28+
test: /(\.jsx|\.js)$/,
29+
loader: 'eslint-loader',
30+
exclude: /node_modules/
31+
}
32+
]
33+
},
34+
resolve: {
35+
modules: [path.resolve('node_modules'), path.resolve('src')],
36+
extensions: ['.json', '.js', '.jsx', '.ts', '.tsx']
37+
},
38+
};
39+
if (mergeWith)
40+
res = _.merge(res, mergeWith);
41+
return res;
42+
}
43+
44+
module.exports.createConfiguration = createConfiguration;

.webpack/webpack.config.dev.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const webpack = require('webpack');
44
const path = require('path');
55
const env = require('yargs').argv.env; // use --env with webpack 2
66
//const CleanWebpackPlugin = require('clean-webpack-plugin');
7-
8-
var process = require('process');
7+
const base = require('./webpack.config.base');
98
const pkg = require('../package.json');
109

1110
let libraryName = pkg.name;
@@ -18,9 +17,9 @@ function _with(obj, objEditFunc) {
1817
/**
1918
* @type {webpack.Configuration}
2019
*/
21-
let config = {
20+
let config = base.createConfiguration({
2221
entry: {
23-
[libraryName]: path.resolve('src/index.js'),
22+
[libraryName]: path.resolve('src/index.ts'),
2423
},
2524
devtool: 'source-map',
2625
mode: 'development',
@@ -32,23 +31,6 @@ let config = {
3231
umdNamedDefine: true,
3332
globalObject: '(typeof global!=="undefined"?global:window)'
3433
},
35-
module: {
36-
rules: [{
37-
test: /(\.jsx|\.js)$/,
38-
loader: 'babel-loader',
39-
exclude: /(node_modules|bower_components)/
40-
},
41-
{
42-
test: /(\.jsx|\.js)$/,
43-
loader: 'eslint-loader',
44-
exclude: /node_modules/
45-
}
46-
]
47-
},
48-
resolve: {
49-
modules: [path.resolve('node_modules'), path.resolve('src')],
50-
extensions: ['.json', '.js', '.jsx']
51-
},
5234
//plugins: plugins,
5335
optimization: {
5436
minimize: false,
@@ -76,15 +58,14 @@ let config = {
7658
providedExports: true,
7759
usedExports: true,
7860
concatenateModules: true,
79-
//includeTest? {chunks:'all'}:false,
8061
},
8162
plugins: [
8263
// new webpack.optimize.CommonsChunkPlugin({
8364
// name: 'manifest'
8465
// })
8566
//new webpack.HashedModuleIdsPlugin()
8667
]
87-
};
68+
});
8869

8970

9071
module.exports = config;

.webpack/webpack.config.prod.js

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ const path = require('path');
33
const env = require('yargs').argv.env; // use --env with webpack 2
44
//const CleanWebpackPlugin = require('clean-webpack-plugin');
55
const UglifyPlugin = require('uglifyjs-webpack-plugin')
6+
//const DeclarationBundlerPlugin = require('declaration-bundler-webpack-plugin')
7+
8+
const base = require('./webpack.config.base');
9+
610

711
const _ = require('lodash');
812

@@ -25,9 +29,9 @@ function createConfig(overrides) {
2529
/**
2630
* @type {webpack.Configuration}
2731
*/
28-
let config = {
32+
let config = base.createConfiguration({
2933
entry: {
30-
[libraryName]: path.resolve('src/index.js'),
34+
[libraryName]: path.resolve('src/index.ts'),
3135
},
3236
//devtool: 'hidden-source-map',
3337
mode: 'production',
@@ -39,30 +43,13 @@ function createConfig(overrides) {
3943
umdNamedDefine: true,
4044
globalObject: '(typeof global!=="undefined"?global:window)'
4145
},
42-
module: {
43-
rules: [{
44-
test: /(\.jsx|\.js)$/,
45-
loader: 'babel-loader',
46-
exclude: /(node_modules|bower_components)/
47-
},
48-
{
49-
test: /(\.jsx|\.js)$/,
50-
loader: 'eslint-loader',
51-
exclude: /node_modules/
52-
}
53-
]
54-
},
55-
resolve: {
56-
modules: [path.resolve('node_modules'), path.resolve('src')],
57-
extensions: ['.json', '.js', '.jsx']
58-
},
5946
optimization: {
6047
minimize: false,
6148
occurrenceOrder: true,
6249
namedModules: true,
6350
namedChunks: true,
64-
splitChunks:{
65-
minSize:200*1024*1024,
51+
splitChunks: {
52+
minSize: 200 * 1024 * 1024,
6653
},
6754
removeAvailableModules: true,
6855
mergeDuplicateChunks: true,
@@ -72,38 +59,43 @@ function createConfig(overrides) {
7259
},
7360
plugins: [
7461
//new webpack.HashedModuleIdsPlugin()
62+
//TODO:
63+
// new DeclarationBundlerPlugin({
64+
// moduleName: `"${libraryName}"`,
65+
// out: './index.d.ts',
66+
// }),
7567
]
76-
};
68+
});
7769

78-
if(overrides) config = _.merge(config, overrides);
70+
if (overrides) config = _.merge(config, overrides);
7971
return config;
8072
}
8173

8274

8375

8476

8577
module.exports = [
86-
createConfig(),//full
87-
88-
//minimized
89-
createConfig({
90-
output:{
91-
filename:'[name].min.js'
92-
},
93-
optimization:{
94-
minimize:true,
95-
minimizer:[
96-
new UglifyPlugin({
97-
uglifyOptions:{
98-
compress:true,
99-
mangle:true,
100-
output:{
101-
comments:false,
102-
},
103-
},
104-
sourceMap:false,
105-
})
106-
]
107-
},
108-
}),
78+
createConfig(), //full
79+
80+
//minimized
81+
createConfig({
82+
output: {
83+
filename: '[name].min.js'
84+
},
85+
optimization: {
86+
minimize: true,
87+
minimizer: [
88+
new UglifyPlugin({
89+
uglifyOptions: {
90+
compress: true,
91+
mangle: true,
92+
output: {
93+
comments: false,
94+
},
95+
},
96+
sourceMap: false,
97+
})
98+
]
99+
},
100+
}),
109101
];

0 commit comments

Comments
 (0)