cd webpack-test
cnpm init
cnpm install webpack --save-dev
dir
源文件目录 mkdir src 静态资源目录 mkdir dist
脚本目录 mkdir script 样式目录 mkdir style
cd dist mkdir js
cd ..
cd src
cd script
echo ... > main.js
main.js内容如下:
function helloWorld(){
}echo ... > index.html 文件名:index.html 内容如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title> <link rel="stylesheet" href=""> </head> <body> <script src="bundle.js"></script> </body> </html>
echo ... > webpack.config.js
webpack.config.js内容如下:
module.exports={
entry:‘./src/script/main.js‘,
output:{
path:‘./dist/js‘,
filename:‘bundle.js‘
}
}cd dist/js dir
ren webpack.config.js webpack.dev.config.js dir
webpack
webpack --config webpack.dev.config.js
{
"name": "webpack-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"webpack":"webpack --config webpack.config.js --progress --display-modules --colors --display-reason"
},
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^2.2.1"
}
}cnpm run webpack
本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1898702
原文:http://suyanzhu.blog.51cto.com/8050189/1898702