首页 > 其他分享 >2018_11_02_04

2018_11_02_04

时间:2024-10-08 22:35:05浏览次数:1  
标签:11 02 vue src loader resolve 2018 config options

vue-cli

案例

const path = require('path');
function resolve(dir) {
  return path.join(__dirname, dir);
}
const targetUrl = '[地址]';
module.exports = {
  // Project deployment base
  // By default we assume your app will be deployed at the root of a domain,
  // e.g. https://www.my-app.com/
  // If your app is deployed at a sub-path, you will need to specify that
  // sub-path here. For example, if your app is deployed at
  // https://www.foobar.com/my-app/
  // then change this to '/my-app/'
  // baseUrl: '/web/app/img/',
  baseUrl: '/',

  // where to output built files
  outputDir: 'dist',

  // whether to use eslint-loader for lint on save.
  // valid values: true | false | 'error'
  // when set to 'error', lint errors will cause compilation to fail.
  lintOnSave: true,

  // use the full build with in-browser compiler?
  // https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
  // compiler: false,

  // tweak internal webpack configuration.
  // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  chainWebpack: config => {
    config.resolve.alias
      .set('@$', resolve('src'))
      .set('common', resolve('src/common'))
      .set('components', resolve('src/components'))
      .set('page', resolve('src/page'))
      .set('config', resolve('src/config'))
      .set('layout', resolve('src/layout'))
      .set('base', resolve('src/base'))
      .set('static', resolve('src/static'));
    config.module
      .rule('pug')
      .test(/\.pug$/)
      .use('pug-html-loader')
      .loader('pug-html-loader')
      .end();
  },
  configureWebpack: () => {},

  // vue-loader options
  // https://vue-loader.vuejs.org/en/options.html
  // vueLoader: {},

  // generate sourceMap for production build?
  productionSourceMap: true,

  // CSS related options
  css: {
    // extract CSS in components into a single CSS file (only in production)
    extract: true,

    // enable CSS source maps?
    sourceMap: false,

    // pass custom options to pre-processor loaders. e.g. to pass options to
    // sass-loader, use { sass: { ... } }
    loaderOptions: {},

    // Enable CSS modules for all css / pre-processor files.
    // This option does not affect *.vue files.
    modules: false,
  },

  // use thread-loader for babel & TS in production build
  // enabled by default if the machine has more than 1 cores
  parallel: require('os').cpus().length > 1,

  // split vendors using autoDLLPlugin?
  // can also be an explicit Array of dependencies to include in the DLL chunk.
  // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#dll-mode
  // dll: false,

  // options for the PWA plugin.
  // see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
  // pwa: {},

  // configure webpack-dev-server behavior
  devServer: {
    open: process.platform === 'darwin',
    host: '0.0.0.0',
    port: 8080,
    https: false,
    hotOnly: false,
    // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#configuring-proxy
    proxy: {
      '/j': {
        target: `${targetUrl}/j`, //设置调用接口域名和端口号别忘了加http
        changeOrigin: true,
        pathRewrite: {
          '^/j': '/', //这里理解成用‘/api’代替target里面的地址,组件中我们调接口时直接用/api代替
          // 比如我要调用'http://0.0:300/user/add',直接写‘/api/user/add’即可 代理后地址栏显示/
        },
      },
      '/o2o': {
        target: `${targetUrl}/o2o`,
        changeOrigin: true,
        pathRewrite: {
          '^/o2o': '/',
        },
      },
      '/moonclub': {
        target: `${targetUrl}/moonclub`,
        changeOrigin: true,
        pathRewrite: {
          '^/moonclub': '/',
        },
      },
    }, // string | Object
    before: app => {},
  },

  // options for 3rd party plugins
  pluginOptions: {
    // ...
  },
};

配置

可参照下面链接中的文章进行配置

在 Vue 项目中(vue-cli2,vue-cli3)使用 pug 简化 HTML 的编写

vue.config.js

webpack.config.js

module: {
  rules: [
    {
      test: /\.vue$/,
      use: [
        {
          loader: 'vue-loader',
          options: {
            loaders: {
              stylus: [
                {
                  loader: 'stylus-resources-loader',
                  options: {
                    resources: './src/assets/_base.styl',
                  },
                },
              ],
            },
          },
        },
      ],
    },
  ],
},

vue.config.js

const path = require('path');
module.exports = {
  chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .tap(options => {
        options.loaders.stylus = options.loaders.stylus.concat({
          loader: 'stylus-resources-loader',
          options: {
            resources: path.resolve('./src/assets/_base.styl'),
          },
        });
        return options;
      });
  },
};

标签:11,02,vue,src,loader,resolve,2018,config,options
From: https://www.cnblogs.com/honghaitao/p/18453199

相关文章

  • 2018_11_02_03
    plugin插件注册importPickerComponentfrom'./picker.vue';let$vm;exportdefault{install(Vue,options){if(!$vm){constpickerPlugin=Vue.extend(PickerComponent);$vm=newpickerPlugin({el:document.createElement......
  • 2018_11_02_02
    jsxJSX这部分内容是在参考文章:在vue中使用jsx语法中提炼出来的,就是跟着敲代码跑了一遍.基本就明白了什么是JSX?JSX就是Javascript和XML结合的一种格式。React发明了JSX,利用HTML语法来创建虚拟DOM。当遇到<,JSX就当HTML解析,遇到{就当JavaScript解析.使用......
  • 2018_11_02_01
    ES5&ES6写法对照表(react)来源:ReactonES6+React/ReactNative的ES5ES6写法对照表class定义语法值得注意的是,我们已经删除了两个括号和一个后缀分号,而对于每个声明的方法,我们都省略了一个冒号,一个function关键字和一个逗号。classPhotoextendsReact.Component......
  • 2018_10_28_01
    动态替换图片最简单的示例<divclass="img-wrapper"><divonclick='replacement'><imgsrc='[图片1]'></div><!-----------------><!--忽略同类型代码.--><!----------------->......
  • NewStar2024-week1
    前言:刚开始比赛,时间比较多尝试了一下所有题目,难度也很友好,之后就写密码了,写全部太累了Week1CryptoBase4C4A575851324332474E324547554B494A5A4446513653434E564D444154545A4B354D45454D434E4959345536544B474D5134513D3D3D3D秒了一眼秒了p,q相近或者factordb查"""fro......
  • NOIP2024集训 Day47 总结
    前言人有两次生命,当他意识到只有一次的时候,第二次生命就开始最小生成树和二分图匹配专题,感觉总体都比较套路。但是这些套路为啥感觉见都没见过啊,怪不得做这么慢。色观察到对于最终答案显然都是最小生成树上一条两个端点颜色不同的边。而这个题并不会改变图的形态,仅仅是改......
  • Cornell cs3110 - Chapter9 Lessons
    使用Menhir构建SimPL的编译器LexerandParser语法分析模块Lexer,Parser,AST是三个依次耦合的模块,可以这么描述三者的关系:Lexer---tokens-->Parser---nodes-->AST相对于上面的图像化描述,cs3110反过来构建整个Lexer和Parser的结构在ast.ml中,定义了AST上......
  • CSP2024-33
    2A题意:给定一个01串,每次可以循环移动一个子串,求多少次操作使整串有序(升序)。每次操作至多使极大全1段个数减一:111100001111\(\to\)000011111111。数一下一开始有多少全1段,判断一下最后一个元素是否是1即可。submissionA题意:给定\(n,m,a,b,k\),求满足\(ax+by=k,\x,......
  • YOLO11改进 | 注意力机制 | 反向残差注意力机制
     秋招面试专栏推荐 :深度学习算法工程师面试问题总结【百面算法工程师】——点击即可跳转......
  • YOLO11改进 | 注意力机制 | 十字交叉注意力机制CrissCrossAttention【含目标检测,语义
    秋招面试专栏推荐 :深度学习算法工程师面试问题总结【百面算法工程师】——点击即可跳转......