sudo npm install webpack -g // -g 代表全局安装webpack,调出命令行即可使用webpack命令 sudo npm install less -g // -g 全局安装 less to css 转换器
mkdir new && cd new
npm init
name: (new)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords: new
author: fz
license: (ISC)
{
"name": "gt",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"new"
],
"author": "fz",
"license": "ISC"
}
Is this ok? (yes)
├── dist // 编译之后输出文件的目录 ├── src // 应用逻辑代码存放区域 │ ├── lib // 存放npm上找不到的第三方库 │ │ ├── backbone.js │ │ └── underscore.js │ ├── static // 存放静态资源 │ │ └── logo.png │ ├── app.html // 部件模板 │ ├── app.js // 部件代码 │ └── app.less // 部件样式 ├── index.html // 应用首页模板 ├── index.js // 应用入口 ├── package.json // 工程配置文件 └── webpack.config.js // webpack配置文件
npm install --save less // 本地按装less npm install --save less-loader // less模块的加载器,配合下面css-loader 和 style-loader npm install --save css-loader // css 模块加载器 npm install --save style-loader // 以上两个插件的根基 npm install --save url-loader // 用来处理 图片 字体 的模块,是由下面file-loader封装的。可自定义文件名 npm install --save file-loader npm install --save html-loader // 加载html文件用的 npm install --save text-loader // 加载纯文本用的 npm install --save html-webpack-plugin // 生成html文件插件 npm install --save extract-text-webpack-plugin // 单独提取css文件插件 npm install --save webpack // 提供webpack对象 npm install --save webpack-dev-server // webpack-server开发包,方便调试 npm install --save vue npm install --save jquery
{
"name": "new",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack-dev-server --hot --inline", // 用户启动 webpack-dev-server 用于用户调试 --hot 代表热替换 , --inline 模式。。不太清楚。
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"new"
],
"author": "fz",
"license": "ISC",
"dependencies": {
"bootstrap": "^3.3.6",
"css-loader": "^0.23.1",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"html-loader": "^0.4.3",
"html-webpack-plugin": "^2.22.0",
"jquery": "^2.1.4",
"less": "^2.7.1",
"less-loader": "^2.2.3",
"style-loader": "^0.13.1",
"text-loader": "0.0.1",
"url-loader": "^0.5.7",
"vue": "^1.0.26",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
}
}
var webpack = require('webpack');
var path = require('path');
var htmlWebpackPlugin = require('html-webpack-plugin');
var extractTextWebpackPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: {
"index": "./index.js",
"common": ['vue', 'jquery', 'underscore', 'backbone']
},
output: {
path: './dist',
publicPath: '/path/',
filename: '[name].[hash].js'
},
module: {
loaders: [
{
test: /\.less$/,
loader: 'style-loader!css-loader!less-loader'
},
{
test: /\.less$/,
loader: extractTextWebpackPlugin.extract("style-loader", "css-loader!less-loader")
// 配合‘extract-text-webpack-plugin'可以剥离,css
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.(png|jpg|gif|woff|woff2|ttf|eot|svg)$/,
loader: 'url-loader?limite=8192' // limit 是转换base64的文件大小的阀值8兆
},
{
test: /\.html$/,
loader: 'html-loader' // 可以用来加载模板
}
]
},
resolve: {
root: [
path.resolve(__dirname, 'src/lib')
],
extensions: ['', '.js'],
alias: {
'underscore': 'underscore.js',
'backbone': 'backbone.js',
}
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
filename: '[name].[hash].js',
chunks: ['index', 'common'] // extract commonChunk from index & common
}),
new htmlWebpackPlugin({
template: './index.html',
filename: 'index.html',
chunks: ['index', 'common']
}),
new webpack.ProvidePlugin({
jQuery: "jquery"
}),
new webpack.optimize.UglifyJsPlugin(),
new extractTextWebpackPlugin("style.css", {
allChunks: true
})
]
};
// index.js
var Vue = require('vue');
var app = new Vue({
el: '#app',
components: {
app: require('./src/app.js')
}
});
// index.html 入口模板 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>vueapp</title> </head> <body id="app"> <app></app> </body> </html>
// app.js
var template = require('./app.html');
require('./app.less');
module.exports = {
template: template,
data: function (){
return {
message: 'hello word!!'
};
}
};
// app.html 视图模板
<div id="div1">
<img src="./static/logo.png" alt="">
<div id="div2">
{{message}}
</div>
</div>
// app.less 视图样式
#div1 {
text-align: center;
}
#div2 {
font-size: 30px;
}
├── dist │ ├── common.6b92c6b075a69a71d22f.js │ ├── index.6b92c6b075a69a71d22f.js │ ├── index.html │ └── style.6b92c6b075a69a71d22f.css
'dev': 'webpack-dev-server --hot --inline'
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有