xuqiang пре 4 година
родитељ
комит
31d26fc9ca
4 измењених фајлова са 85 додато и 48 уклоњено
  1. 48 12
      megalo.config.js
  2. 34 34
      src/main.js
  3. 2 1
      src/pages/home.vue
  4. 1 1
      yarn.lock

+ 48 - 12
megalo.config.js

@@ -1,27 +1,64 @@
+const path = require('path');
 module.exports = {
-    // 构件生产模式时是否启用sourcemap配置(仅在process.env.NODE_ENV === 'production' 时该选项生效)
+    // 构件生产模式时是否生成source map(仅在process.env.NODE_ENV === 'production' 时该选项生效)
     productionSourceMap: false,
 
-    // 是否在开发环境下通过 eslint-loader 在每次保存时 lint 代码
+    // 开启eslint格式化代码
     lintOnSave: true,
 
-    chainWebpack: chainConfig => {
-        // 你可以在这里通过 https://github.com/neutrinojs/webpack-chain 来精细的修改webpack配置
-        console.log('chainWebpack执行了', chainConfig.toString());
-    },
-
     configureWebpack: config => {
-        // 你可以在这里修改webpack的配置并返回,或者直接创建一个新的webpack配置对象返回;
-        // 你的配置将被 webpack-merge 合并 (https://github.com/survivejs/webpack-merge)
+        // 你可以在这里粗放的修改webpack的配置并返回
+        console.log('configureWebpack执行了');
         return config;
     },
+    chainWebpack: chainConfig => {
+        chainConfig.plugin('copy-webpack-plugin').tap(args => {
+            args[0].push({
+                context: path.resolve('src'),
+                from: path.resolve('project.config.json'),
+                to: path.resolve(`dist-${process.env.PLATFORM}/project.config.json`)
+            });
+            args[0].push({
+                context: path.resolve('src'),
+                from: path.resolve('src/vant'),
+                to: path.resolve(`dist-${process.env.PLATFORM}/vant`)
+            });
+            // let str = /usingComponents:[\W](\{[\w\W]+?\})/
+            //     .exec(fs.readFileSync('src/main.js').toString())[1]
+            //     .replace(/[\s]/g, '')
+            //     .replace(/'/g, '"');
+            // console.log(str);
+            // let components = JSON.parse(str);
+            // Object.keys(components).forEach(key => {
+            //     let from = path.resolve('src', components[key].replace(/^\//, ''), '../');
+            //     let to = path.resolve(`dist-${process.env.PLATFORM}`, components[key].replace(/^\//, ''), '../');
+            //     args[0].push({
+            //         context: path.resolve('src'),
+            //         from,
+            //         to
+            //     });
+            //     console.log(from, to);
+            // });
+            return args;
+        });
+        chainConfig.module
+            .rule('less')
+            .test(/\.less$/)
+            .use('style-resources-loader')
+            .loader('style-resources-loader')
+            .options({
+                patterns: [path.resolve(__dirname, './src/styles/common.less')]
+            })
+            .end();
+        // 你可以在这里通过 https://github.com/neutrinojs/webpack-chain 来精细的修改webpack配置
+        // console.log('chainWebpack执行了', chainConfig.toString())
+    },
     // 原生小程序组件存放目录,默认为src/native
     // 如果你有多个平台的原生组件,你应当在此目录下再新建几个子文件夹,我们约定,子文件夹名和平台的名字一致:
     // 微信小程序组件则命名为 'wechat',支付宝为'alipay', 百度为 'swan'
     // 如果只有一个平台,则无需再新建子文件夹
     nativeDir: '/src/native',
 
-    // 文档同 https://cli.vuejs.org/zh/config/#css-loaderoptions
     css: {
         loaderOptions: {
             css: {
@@ -36,9 +73,8 @@ module.exports = {
             stylus: {
                 // https://github.com/shama/stylus-loader
             },
-            // 若不想使用 px2rpx 插件,则设置为 px2rpx: false 即可
+            // https://github.com/megalojs/megalo-px2rpx-loader
             px2rpx: {
-                // https://github.com/megalojs/megalo-px2rpx-loader
                 rpxUnit: 0.5
             }
         }

+ 34 - 34
src/main.js

@@ -51,40 +51,40 @@ export default {
                 }
             ]
         },
-        // usingComponents: {
-        //     'van-image': '/vant/image/index',
-        //     'van-button': '/vant/button/index',
-        //     'van-tabs': '/vant/tabs/index',
-        //     'van-tab': '/vant/tab/index',
-        //     'van-notice-bar': '/vant/notice-bar/index',
-        //     'van-icon': '/vant/icon/index',
-        //     'van-grid-item ': '/vant/grid-item/index',
-        //     'van-count-down': '/vant/count-down/index',
-        //     'van-dialog': '/vant/dialog/index',
-        //     'van-search': '/vant/search/index',
-        //     'van-empty': '/vant/empty/index',
-        //     'van-sticky': '/vant/sticky/index',
-        //     'van-loading': '/vant/loading/index',
-        //     'van-action-sheet': '/vant/action-sheet/index',
-        //     'van-picker': '/vant/picker/index',
-        //     'van-cell-group': '/vant/cell-group/index',
-        //     'van-cell': '/vant/cell/index',
-        //     'van-field': '/vant/field/index',
-        //     'van-uploader': '/vant/uploader/index',
-        //     'van-checkbox': '/vant/checkbox/index',
-        //     'van-panel': '/vant/panel/index',
-        //     'van-overlay': '/vant/overlay/index',
-        //     'van-stepper': '/vant/stepper/index',
-        //     'van-steps': '/vant/steps/index',
-        //     'van-rate': '/vant/rate/index',
-        //     'van-popup': '/vant/popup/index',
-        //     'van-area': '/vant/area/index',
-        //     'van-goods-action': 'vant/goods-action/index',
-        //     'van-goods-action-icon': 'vant/goods-action-icon/index',
-        //     'van-goods-action-button': 'vant/goods-action-button/index',
-        //     'van-calendar': 'vant/calendar/index',
-        //     'van-tree-select': 'vant/tree-select/index'
-        // },
+        usingComponents: {
+            'van-image': '/vant/image/index',
+            'van-button': '/vant/button/index',
+            'van-tabs': '/vant/tabs/index',
+            'van-tab': '/vant/tab/index',
+            'van-notice-bar': '/vant/notice-bar/index',
+            'van-icon': '/vant/icon/index',
+            'van-grid-item ': '/vant/grid-item/index',
+            'van-count-down': '/vant/count-down/index',
+            'van-dialog': '/vant/dialog/index',
+            'van-search': '/vant/search/index',
+            'van-empty': '/vant/empty/index',
+            'van-sticky': '/vant/sticky/index',
+            'van-loading': '/vant/loading/index',
+            'van-action-sheet': '/vant/action-sheet/index',
+            'van-picker': '/vant/picker/index',
+            'van-cell-group': '/vant/cell-group/index',
+            'van-cell': '/vant/cell/index',
+            'van-field': '/vant/field/index',
+            'van-uploader': '/vant/uploader/index',
+            'van-checkbox': '/vant/checkbox/index',
+            'van-panel': '/vant/panel/index',
+            'van-overlay': '/vant/overlay/index',
+            'van-stepper': '/vant/stepper/index',
+            'van-steps': '/vant/steps/index',
+            'van-rate': '/vant/rate/index',
+            'van-popup': '/vant/popup/index',
+            'van-area': '/vant/area/index',
+            'van-goods-action': 'vant/goods-action/index',
+            'van-goods-action-icon': 'vant/goods-action-icon/index',
+            'van-goods-action-button': 'vant/goods-action-button/index',
+            'van-calendar': 'vant/calendar/index',
+            'van-tree-select': 'vant/tree-select/index'
+        },
         window: {
             backgroundTextStyle: 'light',
             navigationBarBackgroundColor: '#fff',

+ 2 - 1
src/pages/home.vue

@@ -104,7 +104,8 @@ export default {
     .top-img {
         width: 375px;
         height: 236px;
-        background: #00ba64;
+        background: @red;
+        // background: #00ba64;
         border-radius: 2px;
 
         .title {

+ 1 - 1
yarn.lock

@@ -8760,7 +8760,7 @@ strip-json-comments@^2.0.1, strip-json-comments@~2.0.1:
 
 style-resources-loader@^1.4.1:
   version "1.4.1"
-  resolved "https://registry.nlark.com/style-resources-loader/download/style-resources-loader-1.4.1.tgz#87f520e6c8120a71e756726c1c53a78c544ca7db"
+  resolved "https://registry.npm.taobao.org/style-resources-loader/download/style-resources-loader-1.4.1.tgz#87f520e6c8120a71e756726c1c53a78c544ca7db"
   integrity sha1-h/Ug5sgSCnHnVnJsHFOnjFRMp9s=
   dependencies:
     glob "^7.1.6"