我正在尝试创建一个包,但是在使用“ vendor”文件夹之前,我需要加载一些.js文件。 结构如下:
-> assets
->js
->controller
->services
->directives
->vendor
app.js
在创建捆绑软件时,它会将app.js放在首位,但我需要将“ vendor”文件夹的.js放在首位。
const webpack = require('webpack')
const path = require('path')
module.exports = {
mode: "development",
entry: {
main:[path.resolve(__dirname, 'assets/js/vendor/jquery.min.js'),
path.resolve(__dirname, 'assets/js/vendor/sha256.min.js'),
path.resolve(__dirname, 'assets/js/vendor/bootstrap.min.js'),
path.resolve(__dirname, 'assets/js/vendor/angular.js'),
path.resolve(__dirname, 'assets/js/vendor/smoothscroll.min.js'),
path.resolve(__dirname, 'assets/js/vendor/jquery.mask.min.js'),
path.resolve(__dirname, 'assets/js/vendor/cpf.min.js'),
path.resolve(__dirname, 'assets/js/vendor/clipboard.min.js'),
path.resolve(__dirname, 'assets/js/vendor/angular-animate.min.js'),
path.resolve(__dirname, 'assets/js/vendor/angular-cookies.min.js'),
path.resolve(__dirname, 'assets/js/vendor/angular-locale_pt-br.js'),
path.resolve(__dirname, 'assets/js/vendor/angular-ui-router.min.js'),
path.resolve(__dirname, 'assets/js/vendor/bootstrap-angular-validation-all.min.js'),
path.resolve(__dirname, 'assets/js/vendor/loading-bar.min.js'),
path.resolve(__dirname, 'assets/js/vendor/nya-bs/nya-bs-select.js'),
path.resolve(__dirname, 'assets/js/vendor/slick/slick.min.js'),
path.resolve(__dirname, 'assets/js/vendor/ngCpfCnpj.js'),
path.resolve(__dirname, 'assets/js/vendor/match-media.js'),
path.resolve(__dirname, 'assets/js/app.js'),
path.resolve(__dirname, 'assets/js/services/message.js'),
path.resolve(__dirname, 'assets/js/services/settings.js'),
path.resolve(__dirname, 'assets/js/services/urlRedeSocial.js'),
]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'temp/builder'),
}
}
答案 0 :(得分:5)
我可能错了,但是我想您正在寻找的是这个
entry: {
app: [
path.resolve(__dirname, 'assets/js/app.js'),
path.resolve(__dirname, 'assets/js/services/message.js'),
path.resolve(__dirname, 'assets/js/services/settings.js'),
path.resolve(__dirname, 'assets/js/services/urlRedeSocial.js'),
],
vendor: [
path.resolve(__dirname, 'assets/js/vendor/jquery.min.js'),
path.resolve(__dirname, 'assets/js/vendor/sha256.min.js'),
path.resolve(__dirname, 'assets/js/vendor/bootstrap.min.js'),
path.resolve(__dirname, 'assets/js/vendor/angular.js'),
path.resolve(__dirname, 'assets/js/vendor/smoothscroll.min.js'),
path.resolve(__dirname, 'assets/js/vendor/jquery.mask.min.js'),
path.resolve(__dirname, 'assets/js/vendor/cpf.min.js'),
path.resolve(__dirname, 'assets/js/vendor/clipboard.min.js'),
path.resolve(__dirname, 'assets/js/vendor/angular-animate.min.js'),
path.resolve(__dirname, 'assets/js/vendor/angular-cookies.min.js'),
path.resolve(__dirname, 'assets/js/vendor/angular-locale_pt-br.js'),
path.resolve(__dirname, 'assets/js/vendor/angular-ui-router.min.js'),
path.resolve(__dirname, 'assets/js/vendor/bootstrap-angular-validation-all.min.js'),
path.resolve(__dirname, 'assets/js/vendor/loading-bar.min.js'),
path.resolve(__dirname, 'assets/js/vendor/nya-bs/nya-bs-select.js'),
path.resolve(__dirname, 'assets/js/vendor/slick/slick.min.js'),
path.resolve(__dirname, 'assets/js/vendor/ngCpfCnpj.js'),
path.resolve(__dirname, 'assets/js/vendor/match-media.js')
]
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'temp/builder'),
}
这将产生两个单独的束。 app.bundle.js
和vendor.bundle.js
。然后,如果您使用的是HtmlWebpackPlugin
,则可以执行以下操作来控制顺序:
new HtmlWebpackPlugin({
chunks: ['vendor', 'app'],
chunksSortMode: 'manual'
})