公司裏的項目,都用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