1 | const config = require("./webpack.config");
|
2 | const merge = require("webpack-merge");
|
3 | const webpack = require('webpack');
|
4 |
|
5 | var pages = require('./plugins/entryFile').getEntryFile().pages;
|
6 |
|
7 | let webpackConfig = merge(config, {
|
8 | module: {
|
9 | rules: [{
|
10 | test: /\.vue(\?[^?]+)?$/,
|
11 | loader: 'weex-loader',
|
12 | options: {
|
13 | }
|
14 | }],
|
15 | },
|
16 | output: {
|
17 | path: light.config.dist,
|
18 | filename: '[name].native.js',
|
19 |
|
20 |
|
21 | chunkFilename: 'lightdist/[name].native.js?[chunkhash]',
|
22 | },
|
23 | plugins: [
|
24 |
|
25 | new webpack.BannerPlugin({
|
26 | banner: '// { "framework": "Vue" }\n var lightGlobal = {};',
|
27 | raw: true
|
28 | }),
|
29 | new webpack.DefinePlugin({
|
30 | 'process.env.RUNTIME': JSON.stringify("native"),
|
31 | 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
32 | '__ENV__': require("./env")(light.options.env || 'default')
|
33 | }),
|
34 | ],
|
35 | externals: {
|
36 | vue: 'Vue'
|
37 | },
|
38 | });
|
39 |
|
40 | if (process.env.NODE_ENV === "dev") {
|
41 | webpackConfig = merge({
|
42 | watch: true,
|
43 | watchOptions: {
|
44 |
|
45 | ignored: (function () {
|
46 | pages.forEach(function (page) {
|
47 | page = pages.length == 1 && pages[0] == 'index' && light.options.page != 'index' ? 'app' : 'index';
|
48 | page += '.native.js';
|
49 | })
|
50 | return pages;
|
51 | })()
|
52 | }
|
53 | }, webpackConfig)
|
54 | }
|
55 |
|
56 | module.exports = {
|
57 | build() {
|
58 | light.util.log("info", "准备编译weex环境下的jsnative文件...");
|
59 |
|
60 |
|
61 | let distConfig = webpackConfig;
|
62 |
|
63 |
|
64 | let buildJS = require("path").join(light.config.src, "build.js");
|
65 | if (require("fs").existsSync(buildJS)) {
|
66 | distConfig = require(buildJS).build(distConfig, merge, webpack)
|
67 | }
|
68 |
|
69 | return distConfig;
|
70 | }
|
71 | }; |
\ | No newline at end of file |