我最近切换到我的项目(Angularjs 1,AdminLTE,SPA)的webpack。使用webpack复制模块
有登录页面和登录页面后。 登录页,我要求的jQuery,引导,角等, 对于登录页面后,我要求所有的上面加数据表中,时刻等
所以我安装我的webpack.config像
var path = require('path');
var webpack = require('webpack');
const basepath = 'resources/assets/js/angular/';
module.exports = {
module: {
rules: [
{test: /\.js$/, exclude: /node_modules/, loader: "babel-loader"},
{test: /\.css$/, loader: 'style-loader!css-loader'}
],
noParse: [/moment-with-locales/]
},
devtool: 'source-map',
entry: {
common: ['jquery','bootstrap', 'fastclick', 'sparklines', 'slimscroll','angular','angular-route', 'oclazyload', 'angular-translate', path.resolve(__dirname, `${basepath}../adminlte/adminlte.js`)],
angular: [path.resolve(__dirname, `${basepath}app.js`), path.resolve(__dirname, `${basepath}service.js`)],
login: path.resolve(__dirname, `${basepath}ctrl/login.js`),
logined: ['datatables.net', 'angular-datatables', 'moment', 'ui-select', 'angular-bootstrap-datetimepicker', path.resolve(__dirname, `${basepath}app2.js`)]
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'public/js')
},
resolve: {
alias: {
jquery: "jquery/src/jquery",
moment: "moment/min/moment-with-locales.js"
}
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ["common"],
minChunks: Infinity
}),
new webpack.ProvidePlugin({
moment: "moment"
})
]
};
但是上面的配置会导致生成logined.js和angular.js中的时刻代码重复 这可能是因为我已经在app.js中调用了angular.module()。run()中的moment 所以依赖被注射到产生的角.js
我想要的是被包含在logined.js中的时刻,我可以在任何地方使用它(用于登录后页面)。
登录页面,我会包括common.js, 和登录页面后,我会包括common.js加logined.js
我不知道如果我的观念是错误的,我是新来的WebPack 。
谢谢