主页 > 手机  > 

使用webpack打包express应用

使用webpack打包express应用
使用 webpack 打包 express 应用 安装 webpack 依赖 pnpm add webpack webpack-cli -D 初始化配置

可以使用命令 webpack init 初始化配置或者直接自己创建 webpack.config.js 文件和增加 npm 脚本: 下面是 npm 脚本 和 webpack.config.js 配置:

// Generated using webpack-cli github /webpack/webpack-cli const path = require("path"); const isProduction = process.env.NODE_ENV == "production"; const config = { entry: "./app.ts", output: { path: path.resolve(__dirname, "dist"), }, plugins: [ // Add your plugins here // Learn more about plugins from webpack.js.org/configuration/plugins/ ], target: "node", module: { rules: [ { test: /\.(ts|tsx)$/i, loader: "ts-loader", exclude: ["/node_modules/"], }, // Add your rules for custom modules here // Learn more about loaders from webpack.js.org/loaders/ ], }, resolve: { extensions: [".tsx", ".ts", ".jsx", ".js", "..."], }, }; module.exports = () => { if (isProduction) { config.mode = "production"; } else { config.mode = "development"; } return config; };

npm 脚本配置:

"scripts": { "dev": "nodemon", "build": "webpack --mode=development", "build:dev": "webpack --mode=development", "build:prod": "webpack --mode=production --node-env=production", "watch": "webpack --watch", "test": "echo \"Error: no test specified\" && exit 1" },
标签:

使用webpack打包express应用由讯客互联手机栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“使用webpack打包express应用