AutoCommit/webpack.config.js

74 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-12-26 17:47:37 +08:00
/*
* Author : OBKoro1
* Date : 2019-12-26 17:42:32
* LastEditors : OBKoro1
2020-12-25 14:46:15 +08:00
* LastEditTime : 2020-12-25 14:35:45
* FilePath : \autoCommit\webpack.config.js
2019-12-26 17:47:37 +08:00
* Description : webpack 配置
* https://github.com/OBKoro1
*/
2020-12-25 14:46:15 +08:00
// @ts-check
2019-12-26 17:47:37 +08:00
2020-12-25 14:46:15 +08:00
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
2019-12-26 17:47:37 +08:00
2020-12-25 14:46:15 +08:00
const outputPathName = 'out';
2019-12-26 17:47:37 +08:00
2020-12-25 14:46:15 +08:00
const pathResolve = (p) => path.resolve(__dirname, p);
2019-12-26 17:47:37 +08:00
2020-12-25 14:46:15 +08:00
/** @type {import('webpack').Configuration} */
2019-12-26 17:47:37 +08:00
const config = {
target: 'node', // vscode插件运行在Node.js环境中 📖 -> https://webpack.js.org/configuration/node/
entry: './src/extension.ts', // 插件的入口文件 📖 -> https://webpack.js.org/configuration/entry-context/
output: {
// 打包好的文件储存在'dist'文件夹中 (请参考package.json), 📖 -> https://webpack.js.org/configuration/output/
path: pathResolve(outputPathName),
filename: 'extension.js',
libraryTarget: 'commonjs2',
2020-12-25 14:46:15 +08:00
devtoolModuleFilenameTemplate: '../[resource-path]',
2019-12-26 17:47:37 +08:00
},
devtool: 'source-map',
externals: {
2020-12-25 14:46:15 +08:00
vscode: 'commonjs vscode', // vscode-module是热更新的临时目录所以要排除掉。 在这里添加其他不应该被webpack打包的文件, 📖 -> https://webpack.js.org/configuration/externals/
2019-12-26 17:47:37 +08:00
},
resolve: {
alias: {
2020-12-25 14:46:15 +08:00
'~': pathResolve('src'),
2019-12-26 17:47:37 +08:00
},
// 支持读取TypeScript和JavaScript文件, 📖 -> https://github.com/TypeStrong/ts-loader
2020-12-25 14:46:15 +08:00
extensions: ['.ts', '.js'],
2019-12-26 17:47:37 +08:00
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
2020-12-25 14:46:15 +08:00
loader: 'ts-loader',
},
],
},
],
2019-12-26 17:47:37 +08:00
},
plugins: [
2020-12-25 14:46:15 +08:00
// @ts-ignore
2019-12-26 17:47:37 +08:00
new CopyWebpackPlugin([
{
from: pathResolve('src/views'),
to: pathResolve(`${outputPathName}/views`),
2020-12-25 14:46:15 +08:00
ignore: ['.*'],
2019-12-26 17:47:37 +08:00
},
{
from: pathResolve('src/assets'),
to: pathResolve(`${outputPathName}/assets`),
2020-12-25 14:46:15 +08:00
ignore: ['.*'],
},
]),
],
};
2019-12-26 17:47:37 +08:00
2020-12-25 14:46:15 +08:00
module.exports = config;