// webpack.production.config.js module.exports = { mode: 'production' // 生产模式 此时压缩代码等 development 为开发模式 此时会开启 sourseMap }
打包的起点 能够是一个 固然也但是多个css
module.exports = { entry: './path/to/my/enrty/file.js' }
const path = require('path') module.exports = { entry: './path/file.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'my-first-webpack.bundle.js' } }
// 先npm安装 后使用 const path = require('path') const config = { output: { filename: 'my-first.js' }, module: { rules: [ {test: /\.txt$/, use: 'raw-loader'} ] } } // “嘿,webpack 编译器,当你碰到「在 require()/import 语句中被解析为 '.txt' 的路径」时,在你对它打包以前,先使用 raw-loader 转换一下。”
说明: loader 被用于转换某些类型的模块,而插件则能够用于执行范围更广的任务。插件的范围包括,从打包优化和压缩,一直到从新定义环境中的变量。插件接口功能极其强大,能够用来处理各类各样的任务。html
const HtmlWebpackPlugin = require('html-webpack-plugin') // npm安装后 引用 const webpack = require('webpack') // 用于访问内置插件 const config = { module: { rules: [ {test: /\.txt$/, 'raw-loader'} ], plugins: [ new HtmlWebpackPlugin({template: './src/index.html'}) ] } } module.exports = config