天天看點

vue/cli 3配置檔案vue.config.js

const webpack = require('webpack')

const path = require('path')

    // const CompressionWebpackPlugin = require('compression-webpack-plugin');

const productionGzipExtensions = ['js', 'css']

module.exports = {

    // 基本路徑

    publicPath: process.env.NODE_ENV === 'production' ? '/production-sub-path/' : './',

    // 輸出檔案目錄

    outputDir: 'dist',

    // eslint-loader 是否在儲存的時候檢查

    pages: {

        index: {

            // page 的入口

            entry: 'src/dyreleaseweb/main.js',

            // 模闆來源

            template: 'public/index.html',

            filename: 'index.html',

            favicon: 'public/logo.ico',

            // 當使用 title 選項時,

            // template 中的 title 标簽需要是 <title><%= htmlWebpackPlugin.options.title %></title>

            title: '通稿稿件2.0',

            // 在這個頁面中包含的塊,預設情況下會包含

            // 提取出來的通用 chunk 和 vendor chunk。

            chunks: ['chunk-vendors', 'chunk-common', 'index']

        },

        topic: {

            entry: 'src/topic/main.js',

            template: 'public/topic.html',

            // 在 dist/index.html 的輸出

            filename: 'topic.html',

            title: 'Topic Page',

        }

        // 當使用隻有入口的字元串格式時,

        // 模闆會被推導為 `public/subpage.html`

        // 并且如果找不到的話,就回退到 `public/index.html`。

        // 輸出檔案名會被推導為 `subpage.html`。

        //   subpage: 'src/subpage/main.js'

    },

    chainWebpack: () => {},

    configureWebpack: {

        plugins: [

            new webpack.ProvidePlugin({

                $: 'jquery',

                jQuery: 'jquery',

                'windows.jQuery': 'jquery'

            })

        ]

    productionSourceMap: true,

    // css相關配置

    css: {

        // 是否使用css分離插件 ExtractTextPlugin

        extract: true,

        // 開啟 CSS source maps?

        sourceMap: false,

        // css預設器配置項

        loaderOptions: {

            css: {

            },

            postcss: {

                /*  ident: 'postcss',

                         plugins: (loader) => [

                             require('postcss-import')({ root: loader.resourcePath }),

                             require('postcss-preset-env')(),

                             require('cssnano')()

                         ] */

            }

        // 啟用 CSS modules for all css / pre-processor files.

        modules: true // 去掉檔案名中的 .module

    // 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,

    // webpack-dev-server 相關配置

    devServer: {

        open: process.platform === 'darwin',

        host: '10.10.0.102',

        port: 8066,

        https: false,

        hotOnly: false,

        proxy: {

            '/api': {

                target: 'http://10.10.0.102:9010/',

                ws: true,

                changeOrigin: true,

                pathRewrite: {

                    '^/api': '/gateway'

                }

            '/foo': {

                target: '<other_url>'

        before: app => {}

    // 第三方插件配置

    pluginOptions: {

        // ...

    }

    // eslint-disable-next-line eol-last

}