1.cd test
2.npm init
3.npm install webpack -g
4.npm install webpack --save-dev
5.touch webpack.config.js index.js index.html
6.webpack 配置
let path = require('path');
let webpack = require('webpack');
module.exports = {
entry: './index.js',
output: {
path: path.join(__dirname, 'dist'), //输出目录的配置,模板、样式、脚本、图片等资源的路径配置都相对于它
filename: "bundle.js"
},
module: {
rules: [
]
}
};
7.运行webpack报错
npm i -g webpack-cli全局安装
npm install webpack webpack-cli -D本项目安装
8.长用配置
package.json
{
"name": "test3",
"version": "1.0.0",
"description": "测试版",
"dependencies": {},
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.18.0",
"browser-sync": "^2.18.2",
"css-loader": "^0.25.0",
"ejs-compiled-loader": "^2.1.1",
"element-ui": "^1.2.5",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"glob": "^7.0.6",
"gulp": "^3.9.1",
"gulp-file-include": "^1.0.0",
"html-loader": "^0.4.3",
"html-webpack-plugin": "^2.22.0",
"iview": "^2.0.0-rc.5",
"node-sass": "^3.7.0",
"raw-loader": "^0.5.1",
"sass-loader": "^4.0.2",
"scss-loader": "0.0.1",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"vue": "^2.2.6",
"vue-loader": "^10.0.2",
"vue-resource": "^1.0.3",
"vue-router": "^2.4.0",
"vue-style-loader": "^1.0.0",
"vue-template-compiler": "^2.2.1",
"vuex": "^2.0.0",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.15.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack-dev-server --hot --inline"
},
"author": "chen"
}
webpack.config.js
let path = require('path');
let webpack = require('webpack');
let serverHost = "localhost";
let HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
path: path.join(__dirname, 'dist'), //输出目录的配置,模板、样式、脚本、图片等资源的路径配置都相对于它
publicPath: '/dist/',
filename: "bundle.js"
},
//加载器
module: {
loaders: [
{
test: /\.vue$/,
loader: "vue-loader"
},
{
test: /\.html$/,
loader: "raw-loader"
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader'
},
{
test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
loader: 'file-loader'
},
{
//图片加载器,雷同file-loader,更适合图片,可以将较小的图片转成base64,减少http请求
//如下配置,将小于8192byte的图片转成base64码
test: /\.(png|jpg|gif)$/,
loader: 'url-loader?limit=8192&name=images/[hash].[ext]'
}
]
},
vue: {
loaders: {
scss: ['vue-style-loader', 'css', 'sass'].join('!')
}
},
plugins: [
new HtmlWebpackPlugin({
title:"test3",
filename:"./dist/index.html",//输出html文件,打包时插入js,不用自己手动引入
inject: 'body', //js插入的位置,true/'head'/'body'/false
hash: true
}),
],
//使用webpack-dev-server
devServer: {
contentBase: './',
host: serverHost,
port: 9090, //默认9090
inline: true, //可以监控js变化
hot: true//热启动
},
//使用vue2.x的一个配置
resolve: {
alias: {vue: 'vue/dist/vue.js'}
}
};
webpack
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1.网页中引入的静态资源多了以后有什么问题??? 2.webpack? 3.webpack-cli 4.在项目中安...
- 开始之前: 1.安装node环境 2.安装npm或者cnpm(我使用的是npm) 3.编辑器使用VSCode 4....
- 1. 创建 index.html 首先在 dist 目录下创建 index.html 文件,其内容如下: 这样,你...
- 安装插件npm install --save-dev copy-webpack-plugin 配置webpack....
- 网易云课堂安装webpack的方法是: npm install webpack -g 按该方法安装成功后,接着查询...