转载请注明出处:
npm install -g webpack
npm install webpack --save-dev
module.exports = 'It workd from content.js'
console.log(require('./content.js'))
webpack ./entry.js bundle.js
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"></head><body><script src="bundle.js"></script></body></html>
输出
It workd from content.js
webpack默认只支持js模块, 要打包css文件需要使用 css-loader处理css文件, style-loader应用样式
npm install css-loader style-loader
body { background-color: yellow;}
console.log(require('./content.js'))require('!style!css!./style.css')
require('!style!css!./style.css')每次都写很长的加载器前缀很麻烦, 可以在编译命令指定加载器绑定到文件后缀名
webpack ./entry.js bundle.js --module-bind "css=style!css"
此时 entry.js可以简化
require('./style.css')
将配置信息添加到 webpack.config.js配置文件后, 每次只需要执行 webpack即可完成打包任务
module.exports = { entry: './entry.js', output: {}}