Wil*_*een 5 javascript reactjs webpack webpack-4
今天我潜入了Webpack的内部,我设法使用了许多有用的功能(通过Webpack加载器),例如CSS模块和Babel转换器.我想用它来制作一个React应用程序(没有create-react-app).
这是我的配置文件:
const HtmlWebPackPlugin = require("html-webpack-plugin");
const path = require('path');
module.exports = {
entry: {
main: './src/index.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.js|jsx$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.html$/,
exclude: /node_modules/,
use: [
{
loader: "html-loader",
options: { minimize: true }
}
]
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
query: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
}
]
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "index.html"
})
]
};
Run Code Online (Sandbox Code Playgroud)
因为我现在有一个入口点,我的整个包被转换成一个JS文件.但是,随着我的反应应用程序的增长,将捆绑包分成多个块可能会更好,这样可以更快地下载它们(这是正确的术语吗?).
| 归档时间: |
|
| 查看次数: |
106 次 |
| 最近记录: |