UNPKG

4.07 kBJavaScriptView Raw
1let webpack = require('webpack');
2
3const config = require("./webpack.config");
4const merge = require("webpack-merge");
5var postcss = require('postcss');
6
7//105231 多页工程下app更名为index
8var pages = require('./plugins/entryFile').getEntryFile().pages;
9function extend(pages, item) {
10 let entryObj = { entry: {} };
11 for (var key in config.entry) {
12 entryObj.entry[key] = item;
13 }
14 return entryObj;
15}
16
17
18let webpackconfig = {
19 output: {
20 path: light.config.dist,
21 //75948 异步视图支持添加反缓存的后缀
22 chunkFilename: 'lightdist/[name].js?[chunkhash]',
23 filename: '[name].js'
24 },
25 module: {
26 rules: [{
27 test: /\.vue$/,
28 loader: 'vue-loader',
29 options: {
30 }
31 }],
32 },
33 plugins: [
34 new webpack.DefinePlugin({
35 'process.env.RUNTIME': JSON.stringify("web"),
36 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
37 '__ENV__': require("./env")(light.options.env || 'default')
38 }),
39 ]
40};
41
42
43//97331 兼容带版本号的jsnative
44//112979 移除 --native
45if (!light.config.plugins || light.config.plugins.toString().indexOf("jsnative") < 0) {
46 webpackconfig.module.rules[0].options.postcss = [
47 require('autoprefixer')({
48 browsers: ['> 0.1%', 'ios >= 8', 'not ie < 12']
49 })
50 ];
51
52 //184573 对于miniapp工程,或者启用miniapp插件的工程,再编译为H5环境时处理页面的px为10rem 使用postcss
53 require("./lib/utils").hasPlugin("miniapp") && webpackconfig.module.rules[0].options.postcss.push(require('postcss-plugin-px2rem')({
54 rootValue: 75,
55 minPixelValue: 1.01
56 }))
57} else {
58
59 webpackconfig.module.rules[0].options.postcss = [
60 // to convert weex exclusive styles.
61 require('postcss-plugin-weex')(),
62 require('autoprefixer')({
63 browsers: ['> 0.1%', 'ios >= 8', 'not ie < 12']
64 }),
65 require('postcss-plugin-px2rem')({
66 // base on 750px standard.
67 rootValue: 75,
68 // to leave 1px alone.
69 minPixelValue: 1.01
70 })
71 ];
72 webpackconfig.module.rules[0].options.compilerModules = [{
73 postTransformNode: el => {
74 // el.staticStyle = `$processStyle(${el.staticStyle})`
75 // el.styleBinding = `$processStyle(${el.styleBinding})`
76 require('weex-vue-precompiler')()(el)
77 }
78 }];
79 //105231 给入口文件合并资源
80 webpackconfig = merge(extend(pages, [`${__dirname}/weex.init.js`,]), webpackconfig);
81
82}
83
84
85
86if (process.env.NODE_ENV === "dev") {
87 // 93781 lighting工程不管是jsn项目还是纯h5项目都在控制台显示二维码-qrcode必须在weex-init之后
88 webpackconfig = merge(webpackconfig,{
89 devtool: 'source-map',
90 //105231 给入口文件合并资源
91 entry: extend(pages, [`${__dirname}/plugins/qrcode.js`, 'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000']).entry,
92 plugins: [
93 new webpack.HotModuleReplacementPlugin({
94 multiStep: false,
95 }),
96 //93779 lighting工程编译时如果是添加了-w选项则在控制台提示用户可以查看编译资源树及分析
97 new (require('webpack-visualizer-plugin'))()
98 ]
99 })
100}
101
102// 61306【lighting】再增加一个参数单独控制是否开启vConsole
103if (light.options.console) {
104 //105231 给入口文件合并资源
105 webpackconfig = merge(extend(pages, [`${__dirname}/plugins/vconsole.js`]), webpackconfig)
106
107}
108
109
110module.exports = {
111 build() {
112 let distConfig = merge(webpackconfig, config);
113
114 // 59972 【lighting】可以考虑在现有约定的基础上开放自定义配置接口(Webpack和Babel)
115 let buildJS = require("path").join(light.config.src, "build.js");
116 if (require("fs").existsSync(buildJS)) {
117 distConfig = require(buildJS).build(distConfig, merge, webpack)
118 }
119
120 return distConfig;
121 }
122};