- 30
- 0
请教各大家一个问题,index.js里面的components.js和mixins.js文件在其他的js里面也引入了,但是打包的时候,这两个没有被打包到common.js里面???只有vue被打包成了vendor.js
// webpack.prod.js
const merge = require('webpack-merge')
const commonConfig = require('./webpack.common.js')
const prodConfig = {
mode: 'production',
// devtool: 'cheap-module-source-map',
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
name : 'vendor',
test: /[\\/]node_modules[\\/]/,
minChunks : 2,
chunks : 'all',
priority: -10,
},
default: {
name: 'common',
minChunks: 2,
chunks : 'all',
priority: -20,
reuseExistingChunk: true,
}
}
}
}
}
module.exports = merge(commonConfig, prodConfig)
// index.js
import '../css/index.css'
import Vue from 'vue'
import '../../public/js/components.js'
import mixins from '../../public/js/mixins.js'
console.log('index red')
var app = new Vue({
mixins: [mixins],
el: '#app',
methods: {
alert () {
window.alert('index')
}
},
created() {
console.log('index created')
}
}) - 共 0 条
- 全部回答
-
核桃奶 普通会员 1楼
Webpack is a popular module bundler that is commonly used for building web applications. It allows developers to split large JavaScript files into smaller chunks that can be loaded more efficiently, reducing the overall file size and improving the performance of the application. One way to split chunks in Webpack is by using the
splitChunksplugin. ThesplitChunksplugin is included in Webpack 4 and higher versions. Here's an example of how to use thesplitChunksplugin to split a large JavaScript file into smaller chunks:- Install the
splitChunksplugin using npm:
bash npm install --save-dev webpack-plugin-cut chunks- In your Webpack configuration file, add the
webpack-plugin-cutandchunksplugins to thepluginsarray:
javascript module.exports = { // ... plugins: [ // ... new webpack.optimize.SplitChunksPlugin({ name: 'myScript.js', chunks: 'all', minSize: 1000000, // in bytes maxSize: 50000000, // in bytes reuseExistingChunk: true, // true by default }), // ... ], // ... };- In your JavaScript file, you can use the
chunkproperty to specify which chunks to split. For example:
```javascript const myScript = require('./myScript.js');
myScript.forEach((chunk) => { // chunk can be any JavaScript chunk }); ```
- Finally, you can load the smaller chunks in your HTML by using the
importstatement. For example:
```html
```
In this example, the
myScript-1.js,myScript-2.js, andmyScript-3.jschunks will be split into smaller chunks and loaded from disk, improving the performance of the application. - Install the
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部

