我在我的reactjs应用程序中使用webpack4进行codesplitting。我使用以下webpack.config.js for reactjs app:
webpack.config.js file:
const config = {
entry: {
client: APP_DIR + '/index.js',
},
output: {
filename: '[name].bundle.dev.js',
path: BUILD_DIR,
publicPath : '/js/',
chunkFilename: '[name].[chunkhash].js'
},
mode : 'development',
module: {
rules: [
{
test: /\.(jsx|js)?$/,
exclude: /(node_modules\/)/,
use: {
loader: "babel-loader",
options: {
presets: ['react', 'es2015','stage-2'], // Transpiles JSX and ES6
}
}
},
{
test: /\.(css)?$/,
use: [
'css-loader',
],
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
}),
};
routes.js文件:
import {HomePage,DetailPage} from './reactcomponents';
export default function() {
return (
<Switch>
<Route exact={true} path = "/" component={HomePage}/>
<Route path = {"/([a-zA-Z0-9\-\ ]*)/abc/([a-zA-Z0-9\-\ ]*)-:listingId"} component={DetailPage}/>
</Switch>
)
}
运行webpack config后,webpack生成4个文件:
webpack4和
中“vendors~visitpage.bundle.js”文件的用途是什么?
为什么“vendors~visitpage.bundle.js”文件正在生成?我缺少任何webpack配置选项吗?
答案 0 :(得分:0)
我建议你阅读本页split-chunks-plugin。
您可以看到webpack将根据这些条件自动拆分块:
有关详情,请参阅拆分块插件文档