UNPKG

4.46 kBJavaScriptView Raw
1let webpack = require('webpack');
2
3process.traceDeprecation = false;
4process.noDeprecation = true;
5
6var pages = require('./plugins/entryFile').getEntryFile().pages;
7
8const babelOptions = {
9 presets: [
10 require('babel-preset-env'),
11 require('babel-preset-stage-0'),
12 ],
13 plugins: [
14 // require('babel-plugin-transform-runtime'),
15 require('babel-plugin-syntax-dynamic-import'),
16 require("babel-plugin-transform-class-properties"),
17 // lighting支持jsx编译
18 require('babel-plugin-syntax-jsx'),
19 require('babel-plugin-transform-vue-jsx')
20 ],
21 compact: 'auto',
22 //73460 light工程中lib目录中存在node_modules目录中的ethjs-util模块时编译不报错,打包报错的问题处理
23 babelrc:false,
24 //94259 lighting中编译支持缓存,提高编译效率
25 // cacheDirectory:require("path").join(require("os").tmpdir(),'LIGHTING_WEBPACK_CACHE')
26};
27
28
29
30// 91743 多页工程
31var entryArr = {};
32if (pages && pages.length > 0) {
33 pages.forEach(function (page) {
34 //105231 指定多页工程的入口文件
35 let entry = {};
36 let key = pages.length == 1 && pages[0] == 'index' && light.options.page != 'index' ? 'app' : page;
37 let mainjs = page == 'index' ? 'app' : page;
38 entry[key] = [`${light.config.dist}/view/${page}.js`];
39
40 //118407 lighting支持当light工程不存在app.js时的打包
41 const appFile = `${light.config.dist}/${mainjs}.js`;
42 if(light.util.existsSync(appFile)){
43 entry[key].push(appFile);
44 }
45 entryArr = Object.assign(entryArr, entry)
46 })
47}
48//bug94269 缓存时图片不添加时间戳后缀
49let imghash = light.config.plugins && light.config.plugins.toString().indexOf('cachemanifest') > -1;
50
51let config = {
52 entry: entryArr,
53 module: {
54 rules: [
55 {
56 test: /\.(less|css)$/,
57 use: [{
58 loader: "style-loader" // creates style nodes from JS strings
59 }, {
60 loader: "css-loader" // translates CSS into CommonJS
61 }, {
62 loader: "less-loader" // compiles Less to CSS
63 }]
64 },
65 {
66 test: /\.js$/,
67 //去除node_modules目录的es6转es5流程,加快编译速度
68 exclude: process.env.NODE_ENV === "dev" ? [function (file) {
69 return /(node_modules\/[^(olight)]|bower_components)/ig.test(file)
70 }] : undefined,
71 loader: 'babel-loader',
72 options:babelOptions
73
74 },
75 {
76 test: /\.(png|jpg|gif|svg|ttf|woff|eot|otf)$/,
77 loader: 'file-loader',
78 options: {
79 name: imghash ? 'lightdist/[name].[ext]' : 'lightdist/[name].[ext]?[hash]'
80 }
81 }
82 ]
83 },
84 resolve: {
85 extensions: ['.js', '.vue', '.json'],
86 modules: [`${__dirname}/node_modules`, "lib/node_modules", "lib", "node_modules",`${__dirname}/..`],
87 alias: {
88 "light": `olight`,
89 'vue': "vue/dist/vue.esm",
90 "@":light.config.dist
91 }
92
93 },
94 plugins: [
95 new require('progress-bar-webpack-plugin')({
96 format: ' 编译中 [:bar] ' + require("chalk").green.bold(':percent') + ' (:elapsed 秒)',
97 clear: false
98 }),
99 new webpack.NoEmitOnErrorsPlugin(),
100 new (require("./plugins/loader"))({
101 babel: babelOptions
102 })
103 ],
104 resolveLoader: {
105 modules: [`${__dirname}/node_modules`, "lib/node_modules", "lib", "node_modules",`${__dirname}/..`]
106 }
107};
108
109//102711 vue代码中有错误,比如import写错,使用light release -p 打包,无法报错
110if(!light.options.watch){
111 config.plugins.push(function(){
112 this.plugin("done", function(stats)
113 {
114 if (stats.compilation.errors && stats.compilation.errors.length)
115 {
116 console.log(stats.compilation.errors.toString().red);
117 process.exit(1);
118 }
119 });
120 })
121}
122
123if (light.options.uglify) {
124 config = require("webpack-merge")({
125 plugins: [
126 new webpack.optimize.UglifyJsPlugin({
127 compress: {
128 warnings: false
129 }
130 })
131 ]
132 }, config)
133}
134
135module.exports = config;