切ts ing,js文件转ts后缀

This commit is contained in:
godbasin
2018-12-20 10:44:00 +08:00
parent 103647984e
commit cecd40a4ce
25 changed files with 1365 additions and 26 deletions

1279
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -27,6 +27,8 @@
"webpack": "latest"
},
"devDependencies": {
"ts-loader": "^5.3.1",
"typescript": "^3.2.2",
"webpack-cli": "^2.1.3"
}
}

17
renameJsFile.js Normal file
View File

@@ -0,0 +1,17 @@
var fs = require('fs'),
path = require('path'),
dir = './src/util',
match = RegExp('.js', 'g'),
replace = '.ts',
files;
files = fs.readdirSync(dir);
files.filter(function(file) {
return file.match(match);
}).forEach(function(file) {
var filePath = path.join(dir, file),
newFilePath = path.join(dir, file.replace(match, replace));
console.log({filePath, newFilePath})
fs.renameSync(filePath, newFilePath);
});

9
tsconfig.json Normal file
View File

@@ -0,0 +1,9 @@
{
"compilerOptions": {
"outDir": "./build/",
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"allowJs": true
}
}

5
typings/wx.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
// 临时解决微信ts
declare var wx: any;
declare function Component(...args: any[]): any;
declare function requirePlugin(pluginName: string): any;
type TODO = any;

View File

@@ -1,13 +1,26 @@
let path = require('path');
let webpack = require('webpack');
let pk = require('./package.json');
let path = require("path");
let webpack = require("webpack");
let pk = require("./package.json");
module.exports = [{
mode: 'production',
entry: './src/index.js',
module.exports = [
{
mode: "production",
entry: "./src/index.ts",
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
output: {
path: path.join(__dirname, 'build'),
filename: 'weRequest.min.js',
path: path.join(__dirname, "build"),
filename: "weRequest.min.js",
library: "weRequest",
libraryTarget: "commonjs-module"
},
@@ -16,19 +29,33 @@ module.exports = [{
banner: `weRequest ${pk.version}\n${pk.homepage}`
})
]
}, {
mode: 'development',
entry: './src/index.js',
},
{
mode: "development",
entry: "./src/index.ts",
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
output: {
path: path.join(__dirname, 'build'),
filename: 'weRequest.js',
path: path.join(__dirname, "build"),
filename: "weRequest.js",
library: "weRequest",
libraryTarget: "commonjs-module"
},
devtool: 'inline-source-map',
devtool: "inline-source-map",
plugins: [
new webpack.BannerPlugin({
banner: `weRequest ${pk.version}\n${pk.homepage}`
})
]
}]
}
];