赞
踩
The 'mode' option has not been set, webpack will fallback to 'production' for this value
ERROR in Entry module not found: Error: Can not resolve './src' in 'D:\L-react\HeiMa\01.webpack-base'
webpack-dev-server
html-webpack-plugin
npm init -y
src
源代码目录和dist
产品目录index.html
cnpm i webpack -D
cnpm i webpack-cli -D
webpack
常见报错The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
mode
mode
. production属性,会默认对文件进行压缩.ERROR in Entry module not found: Error: Can not resolve './src' in 'D:\L-react\HeiMa\01.webpack-base'
./src/index.js
./dist/main.js
mopdule.exports
or export default
<script src="../dist/main.js"></script>
cnpm i webpack-dev-server -D
webpack-dev-server
启动.Project is running at http://localhost:8080
: 项目正在8080端口运行(此时是一个小型的服务器)webpack output is served from /
: 托管的的路径是根路径. 在此项目中即: 01.webpack-base[所做事情]
--open
: 自动打开浏览器--port 3000
: 指定端口--hot
: 热更新--progress
: 打包记录--compress
: 压缩--host 127.0.0.1
: 指定主机ipcnpm i html-webpack-plugin -D
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const htmlPlugin = new HtmlWebpackPlugin({
template: path.join(__dirname, './src/index.html'), // 源文件
filename: 'index.html' // 生成在内存中首页的名称
})
module.exports = {
mode: 'development',
plugins: [
htmlPlugin
]
}
[所做事情]:
<script type="text/javacript" src="main.js"></script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。