UNPKG

2.25 kBJavaScriptView Raw
1const config = require("./webpack.config");
2const merge = require("webpack-merge");
3const webpack = require('webpack');
4//105231 app.js->index.js
5var pages = require('./plugins/entryFile').getEntryFile().pages;
6
7let 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 //87143 lighting框架支持jsn视图的异步视图和单独处理
21 chunkFilename: 'lightdist/[name].native.js?[chunkhash]',
22 },
23 plugins: [
24 //144595 type-vue异步视图移除对global的依赖,global->lightGlobal
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
40if (process.env.NODE_ENV === "dev") {
41 webpackConfig = merge({
42 watch: true,
43 watchOptions: {
44 ////105231 多页工程的每个.native.js文件都不监听变化
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
56module.exports = {
57 build() {
58 light.util.log("info", "准备编译weex环境下的jsnative文件...");
59
60
61 let distConfig = webpackConfig;
62 // 59972 【lighting】可以考虑在现有约定的基础上开放自定义配置接口(Webpack和Babel)
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