仿B站项目——(2)环境配置,文件目录
环境配置
主要参考入门Webpack,看这篇就够了,webpack入门和webpack实用配置。
实用开发环境
利用下面的webpack.json
和webpack.config.js
可以搭建一个使用ejs和sass的实用开发环境。
webpack.json
"devDependencies": {
"autoprefixer": "^8.1.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-runtime": "^6.26.0",
"css-loader": "^0.28.10",
"ejs-compiled-loader": "^1.1.0",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.11",
"html-webpack-inline-source-plugin": "0.0.10",
"html-webpack-plugin": "^3.0.6",
"image-webpack-loader": "^4.1.0",
"postcss-loader": "^2.1.1",
"style-loader": "^0.20.3",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.11",
"webpack-dev-server": "^3.1.1"
},
webpack.config.js
//webpack.config.js
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
//const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
devtool: 'none',
entry: {
index: './src/page/index.js'
},
output: {
path: path.resolve(__dirname, 'build'),
publicPath: '/dist/', //相对路径替换
filename: 'bundle-[hash].js'
},
devServer: {
port: 3030, //端口
contentBase: './public', //本地服务器所加载的页面所在的目录
historyApiFallback: true, //不跳转
inline: true, //实时刷新
hot: true
},
watchOptions: {
poll: 1000, //监测修改的时间(ms)
aggregateTimeout: 500, //防止重复按键,500毫秒内算按一次
ignored: /node_modules/, //不监测
},
module: {
rules: [
{
test: /\.jsx|\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true, //启用缓存
plugins: ['transform-runtime']
}
}
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: false, //是否启用css-module
localIdentName: '[name]__[local]' //类名转换
}
},
{
loader: 'postcss-loader',
options: {
plugins: [
require('autoprefixer')
]
}
},
'sass-loader'
]
},
{
test: /\.(png|jpg|gif|svg)$/i,
use:[
'url-loader?limit=8192&name=[name]-[hash:5].[ext]',
{
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
quality: 65
},
optipng: {
enabled: false,
},
pngquant: {
quality: 80,
speed: 4
},
gifsicle: {
interlaced: false,
},
webp: {
quality: 75
}
}
}
]
}
]
},
plugins: [
new webpack.BannerPlugin('This file is created by sishenhei7'),
//使用模板生成html文件
new HtmlWebpackPlugin({
filename:'index.html',
template: 'ejs-compiled-loader!src/page/template.html',
title:'this is index',
chunks: ['index']
}),
new webpack.HotModuleReplacementPlugin() //热加载插件
//new ExtractTextPlugin('styles.css') //把CSS文件分离出来
]
};
目录生成
踩坑:果然目录生成要在前端工程里面完成,因为环境配置要利用目录来设置路径。
我自己思考的目录是这样的:
├── src
│ ├── config
│ │ └── configX.js #配置文件
│ ├── page
│ │ ├── pageX.js #页面入口
│ │ └── pageX.ejs #页面模板
│ ├── static
│ │ ├── .js #静态js比如jQuery.js
│ │ ├── .css #静态css比如normalize.css
│ │ └── .jpg #静态图片
│ └── component #各个模块
│ └── widgetX
│ ├── .scss
│ ├── .js
│ ├── .html
│ ├── .jpg
│ └── test #单元测试(暂时没有)
│ └── test.js
├── mobile #手机端(暂时没有)
├── dist #打包文件夹
│ ├── assets #各种css, js, image资源
│ │ ├── .css
│ │ ├── .js
│ │ └── .jpg
│ └── pageX.html #各种页面
├── record
│ └── record.md #项目记录
├── .babelrc #babel配置文件
├── .gitignore #git配置文件,哪些不上传git
├── package-lock.json
├── package.json
├── README.md
└── webpack.config.js
仿B站项目——(2)环境配置,文件目录的更多相关文章
- 仿B站项目(3)页面配置
页面配置 B站有很多页面,比如说首页啊,动画页啊,音乐页啊,舞蹈页啊,那就从首页开始. 通过观察首页,可以看见有很多模块除了内容之外,在布局颜色等方面都是一样的,所以我可以开发一些模板或者插件,到时候 ...
- 仿B站项目——(1)计划,前端工程
计划 现打算: 计划用webpack打包 + 模板语言 + jquery + jquery ui + bootstrap做一个仿B站的静态网站. 网站兼容手机浏览器端. 部分模块打算仿照SPA用js加 ...
- 使用EmBitz开发STM32项目的环境配置
一.EmBitz软件获取与安装 1.EmBitz软件的获取 EmBitz原名Em::Blocks,是基于Code::Blocks开发的,面向嵌入式的C/C++集成开发环境.支持J-Link和ST-Li ...
- vue项目eslint环境配置与vscode配置eslint
eslint基础环境搭建 全局安装eslint:npm install eslint -g 项目eslint初始化:eslint --init,按团队或自己的编程风格回答三道题. ? How woul ...
- node.js项目多环境配置
配置多种场景 我们的系统是要在不同的环境下运行的,不同的环境可能是不同的端口号,不同的数据库地址,数据库用户和密码, 并且可能有的需要自动重启有的不需要自动重启. 我们在有一个配置的时候是无法满足这么 ...
- 前端 vue-cli+Webpack 项目开发环境配置、创建一个vue-demo
一.软件及命令: (1)下载node.js 最新的LTS 版本,下载 msi格式的(直接点击安装即可). (2)命令1:npm install cnpm -g 命令2:cnpm install web ...
- vue 的准备项目架构环境配置
一.环境搭建 中国镜像 composer config repo.packagist composer https://packagist.phpcomposer.com 命令 composer in ...
- python项目离线环境配置指南
参考文献: http://blog.csdn.net/candcplusplus/article/details/52156324 https://www.cnblogs.com/michael-xi ...
- vue2.0项目的环境配置以及有哪些的坑
npm run dev项目运行:$ git pull origin master 更新代码项目的提交代码git push -u origin master 这里就开始准备提交到网络上了 项目的地址gi ...
随机推荐
- proposal-cancelable-promises
fetch 从来就没行过,最大的优势就是"新标准",但是 proposal-cancelable-promises 被 withdrawn,就导致了 fetch 发起的请求不可能被 ...
- Tomcat-servlet基础
1.1 概念 运行在服务器上的小程序 定义了浏览器访问到(tomact)的规则 1.2 步骤 1.3 执行原理 1 当服务器 接收到客户端浏览器的请求后 会解析url地址 获得url路径 ...
- mongodb安装及配置
下载安装篇 MongoDB 提供了 linux 各发行版本 64 位的安装包,你可以在官网下载安装包. 下载地址:https://www.mongodb.com/download-center#com ...
- 九、Brideg 桥接模式
设计原理: 代码清单: 抽象类 DisplayImpl public abstract class DisplayImpl { public abstract void rawOpen(); publ ...
- Python开发【第七篇】:面向对象二
字段 class Foo: #静态字段(保存在类中) CC = 123 def __init__(self): #普通字段(保存在对象中) ...
- Newtonsoft.Json反序列化(Deserialize)出错:Bad JSON escape sequence
使用Newtonsoft.Json反序列化收到的字串为JObject或其它支持的数据模型,有时错误,提示如下: Bad JSON escape sequence: \c. Path , positio ...
- 556. Next Greater Element III下一个更大的数字
[抄题]: Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exac ...
- [leetcode]52. N-Queens II N皇后
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...
- mybatis进阶-5resultMap总结
resultType: 作用: 将查询结果按照sql列名pojo属性名一致性映射到pojo中. 场合: 常见一些明细记录的展示,比如用户购买商品明细,将关联查询信息全部展示在页面时,此时可直接使用re ...
- 1,postman的安装
1,下载postman 2,安装,下载和自己系统相对应的版本 本人下载的是window版本的,直接一步步安装就行 打开后进入下边的界面 建议使用native版本的postman,chrome插件的po ...