公司里的项目,都用webpack了,上周忙于完成业务逻辑的实现,对webpack只是有个大概的印象。这周终于有时间来好好学习总结一番了。css
通常状况下学习新的东西,我喜欢去知乎去了解这个技术是用来作什么的、为什么项目里须要用这个技术,而后再去官网学习。不过对于webpack,知乎和官网上都看的一头雾水。html
下面的3个连接,算是我找到的比较好的入门文章了。跟着教程敲了几遍代码,今天就把知识点串一下吧,也加深一下本身对webpack的理解。vue
//Webpack配置 var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); module.exports = { entry: __dirname + "/app/main.js",//惟一入口文件 output: { path: __dirname + "/build", filename: "[name]-[hash].js"//打包后的js文件 }, module: { loaders: [ { test: /\.json$/, loader: "json" }, { test: /\.js$/, exclude: /node_modules/, loader: 'babel' }, { test: /\.css$/, loader: ExtractTextPlugin.extract('style', 'css?modules!postcss') } ] }, postcss: [ require('autoprefixer') ], plugins: [ new HtmlWebpackPlugin({ template: __dirname + "/app/index.tmpl.html" }), new webpack.optimize.OccurenceOrderPlugin(), new webpack.optimize.UglifyJsPlugin(), new ExtractTextPlugin("[name]-[hash].css") ] }
参考连接node
http://www.pro-react.com/materials/appendixA/react
https://fakefish.github.io/react-webpack-cookbook/Introduction-to-Webpack.htmlwebpack
https://www.zfanw.com/blog/webpack-tutorial.html#i-2git