标签:直接 引入 conf dir entry chunk style mon index
一、准备
--npm init,初始化package.json
--npm install webpack --save-dev
工程根目录新建webpack.config.js,用于webpack打包配置
二、打包配置
var path = require(‘path‘); var webpack = require(‘webpack‘); var htmlPlugin = require(‘html-webpack-plugin‘); module.exports = { entry: { index1: ‘./index.js‘, index2: ‘./index2.js‘ }, output: { path: path.resolve(__dirname,‘dist‘), filename: ‘js/[name]-[chunkhash].bundle.js‘ }, plugins: [ new htmlPlugin({ title: ‘Webpack1234‘, filename: ‘webpack.demo.html‘, template: ‘index.html‘, }) ] };
--webpack模块的引入类似与CMD,CommonJS,故可直接使用require()来引入相关模块
1、Entry(三种格式)
单一字符串:entry: ‘./main.js‘
字符串数组:entry: [‘./main.js‘, ‘./main2.js‘]
对象: entry: {
a: ‘./main.js‘, -------->trunkName: 路径
b: ‘./main2.js‘ -------->trunkName: 路径
}
2、Output
{
path: ‘‘ -----绝对路径
filename: ‘bundle.js‘
},
若入口有多个trunk时,filename应为:‘[name].bundle.js’
标签:直接 引入 conf dir entry chunk style mon index
原文地址:http://www.cnblogs.com/Drose/p/7450670.html