记录一下使用typescript开发chrome扩展的相关配置。
必定需要用到的开发依赖项:
npm install chrome-types webpack-cli ts-loader typescript copy-webpack-plugin --save-dev
npx tsc --init
const path = require('path');
const CopyPlugin = require("copy-webpack-plugin");
module.exports = {
mode: 'production',
entry: {
index: {
import: './src/index.ts',
filename: 'index.js'
},
background: {
import: './src/background.ts',
filename: 'background.js'
}
},
plugins: [
new CopyPlugin({
patterns: [
{ from: "public", to: "" },
],
}),
],
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
clean: true
},
};
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack build"
}
chrome使用typescript目录结构