1 | let webpack = require('webpack');
|
2 |
|
3 | const config = require("./webpack.config");
|
4 | const merge = require("webpack-merge");
|
5 | var postcss = require('postcss');
|
6 |
|
7 |
|
8 | var pages = require('./plugins/entryFile').getEntryFile().pages;
|
9 | function 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 |
|
18 | let webpackconfig = {
|
19 | output: {
|
20 | path: light.config.dist,
|
21 |
|
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 |
|
44 |
|
45 | if (!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 |
|
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 |
|
61 | require('postcss-plugin-weex')(),
|
62 | require('autoprefixer')({
|
63 | browsers: ['> 0.1%', 'ios >= 8', 'not ie < 12']
|
64 | }),
|
65 | require('postcss-plugin-px2rem')({
|
66 |
|
67 | rootValue: 75,
|
68 |
|
69 | minPixelValue: 1.01
|
70 | })
|
71 | ];
|
72 | webpackconfig.module.rules[0].options.compilerModules = [{
|
73 | postTransformNode: el => {
|
74 |
|
75 |
|
76 | require('weex-vue-precompiler')()(el)
|
77 | }
|
78 | }];
|
79 |
|
80 | webpackconfig = merge(extend(pages, [`${__dirname}/weex.init.js`,]), webpackconfig);
|
81 |
|
82 | }
|
83 |
|
84 |
|
85 |
|
86 | if (process.env.NODE_ENV === "dev") {
|
87 |
|
88 | webpackconfig = merge(webpackconfig,{
|
89 | devtool: 'source-map',
|
90 |
|
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 |
|
97 | new (require('webpack-visualizer-plugin'))()
|
98 | ]
|
99 | })
|
100 | }
|
101 |
|
102 |
|
103 | if (light.options.console) {
|
104 |
|
105 | webpackconfig = merge(extend(pages, [`${__dirname}/plugins/vconsole.js`]), webpackconfig)
|
106 |
|
107 | }
|
108 |
|
109 |
|
110 | module.exports = {
|
111 | build() {
|
112 | let distConfig = merge(webpackconfig, config);
|
113 |
|
114 |
|
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 | };
|