第一次手打webpack.config.js,错了也要作个记录。
贵在坚持,最近到年底,尽量练习完新书---《web全栈项目开发入门与实战》。
webpack.config.js
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
mode: 'development',
entry: {
first: './src/first.js',
second: './src/second.js'
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
publicPath: './'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
'env',
'react',
'es2015',
'stage-0'],
plugins: [
'transform-runtime',
'add-module-exports'
]
}
}
]
},
{
test: /.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /.less$/,
use: [
'style-loader',
'css-loader',
'less-loader'
]
},
{
test: /.(jpg|png|gif|svg)$/,
use: [
'user-loader?limit=8192&name=./[name].[ext]'
]
},
{
test: /\.(git|png|jpe?g|eot|woff|ttf|svg|pdf)$/,
use: [
'file-loader'
]
}
]
},
plugins: [
new ExtractTextPlugin('style.css')
],
devServer: {
contentBase: path.resolve(__dirname, './dist'),
host: 'localhost',
compress: true,
port: 8000,
host: true
}
};
2020-09-21 21_51_44-secondary_webpack.config.js - HBuilder X 2.6.1.png