-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b3c332
commit b1412d2
Showing
4 changed files
with
92 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const path = require('path'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const { CleanWebpackPlugin } = require('clean-webpack-plugin'); | ||
|
||
const commonConfig = { | ||
module: { // 让 webpack 能够去处理那些非 JavaScript 文件 | ||
rules: [{ | ||
test: /\.js$/, // 注意这里要写正确,不然useBuiltIns不起作用 | ||
exclude: /node_modules/, // 排除node_modules中的代码 | ||
use: [{ | ||
loader: 'babel-loader', // 只是babel和webpack之间的桥梁,并不会将代码转译 | ||
}] | ||
}, { | ||
test: /\.less$/, | ||
exclude: /node_modules/, | ||
use: ['style-loader', | ||
{ | ||
loader: 'css-loader', | ||
options: { | ||
importLoaders: 2 | ||
} | ||
}, 'less-loader', 'postcss-loader'] | ||
}, | ||
{ | ||
test: /\.css$/, | ||
use: ['style-loader', 'css-loader', 'postcss-loader'] | ||
}, | ||
{ | ||
test: /\.(png|jpg|gif|jpeg)$/, | ||
use: { | ||
loader: 'url-loader', | ||
options: { | ||
name: '[name]_[hash].[ext]', // placeholder 占位符 | ||
outputPath: 'images/', // 打包文件名 | ||
limit: 204800, // 小于200kb则打包到js文件里,大于则打包到imgages里 | ||
}, | ||
}, | ||
}, | ||
{ | ||
test: /\.(eot|woff2?|ttf|svg)$/, | ||
use: { | ||
loader: 'url-loader', | ||
options: { | ||
name: '[name]-[hash:5].min.[ext]', | ||
outputPath: 'fonts/', | ||
limit: 5000, | ||
} | ||
}, | ||
}] | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin({ // 向dist文件中自动添加模版html | ||
template: 'src/index.html', | ||
}), | ||
new CleanWebpackPlugin(), // 打包后先清除dist文件,先于HtmlWebpackPlugin运行 | ||
], | ||
output: { | ||
publicPath: "/", | ||
filename: 'bundle.js', // 打包后文件名称 | ||
path: path.resolve(__dirname, '../dist') // 打包后文件夹存放路径 | ||
} | ||
} | ||
|
||
module.exports = commonConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const merge = require('webpack-merge'); | ||
const commonConfig = require('./webpack.common.js'); | ||
|
||
const prodConfig = { | ||
mode: "production", // 只要在生产模式下, 代码就会自动压缩 | ||
devtool:"cheap-module-source-map", | ||
entry: { | ||
main: './src/index.js' | ||
}, | ||
module: {}, | ||
plugins: [], | ||
output: {} | ||
} | ||
|
||
module.exports = merge.smart(commonConfig, prodConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters