|
| 1 | +/* |
| 2 | + * @Author: wangshan |
| 3 | + * @Date: 2021-06-22 01:31:05 |
| 4 | + * @LastEditors: wangshan |
| 5 | + * @LastEditTime: 2021-10-17 18:12:49 |
| 6 | + * @Description: |
| 7 | + */ |
| 8 | +// import "@babel/polyfill"; // 所有模块项导入前导入babel/polyfill |
| 9 | + |
| 10 | +const path = require("path"); |
| 11 | +const { CleanWebpackPlugin } = require("clean-webpack-plugin"); |
| 12 | +const HtmlWebpackPlugin = require("html-webpack-plugin"); |
| 13 | +const BundleAnalyzerPlugin = |
| 14 | + require("webpack-bundle-analyzer").BundleAnalyzerPlugin; // 分析打包后包体积 |
| 15 | +const currdir = __dirname; |
| 16 | +module.exports = { |
| 17 | + entry: path.resolve(currdir, "../src/index.ts"), |
| 18 | + output: { |
| 19 | + path: path.resolve(currdir, "../dist"), |
| 20 | + filename: "js/[name].[hash:8].js", |
| 21 | + chunkFilename: "js/[name].[hash:8].js", // 入口文件内懒加载模块文件推断打包 |
| 22 | + }, |
| 23 | + module: { |
| 24 | + // loader配置 |
| 25 | + rules: [ |
| 26 | + { |
| 27 | + test: /\.ts$/, |
| 28 | + use: { |
| 29 | + loader: "ts-loader", |
| 30 | + options: { |
| 31 | + transpileOnly: true, // 只做语言转换,而不做类型检查 |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + { |
| 36 | + test: /\.js$/, |
| 37 | + use: { |
| 38 | + loader: "babel-loader", |
| 39 | + options: { |
| 40 | + presets: ["@babel/preset-env", { modules: false }], // 设置modules完全开启tree-shaeking |
| 41 | + }, |
| 42 | + }, |
| 43 | + exclude: /node_modules/, |
| 44 | + }, |
| 45 | + ], |
| 46 | + }, |
| 47 | + resolve: { |
| 48 | + alias: { |
| 49 | + // 模块查询路径配置 |
| 50 | + "@": "../src", |
| 51 | + }, |
| 52 | + extensions: ["*", ".ts", ".js", ".json"], // 模块文件解析顺序;能够在引入模块时不带扩展 |
| 53 | + }, |
| 54 | + plugins: [ |
| 55 | + new CleanWebpackPlugin(), |
| 56 | + // new BundleAnalyzerPlugin(), |
| 57 | + new HtmlWebpackPlugin({ |
| 58 | + // 使用插件,使用自定义插件 |
| 59 | + template: path.resolve(currdir, "../public/index.html"), |
| 60 | + }), |
| 61 | + ], |
| 62 | +}; |
0 commit comments