1

我有一个使用此配置运行的 Vuejs 应用程序:

const BundleTracker = require("webpack-bundle-tracker");

module.exports = {
// on Windows you might want to set publicPath: "http://127.0.0.1:8080/" 
 publicPath: "http://0.0.0.0:8080/", 
 outputDir: './dist/', 

 chainWebpack: config => {

    config
        .plugin('BundleTracker')
        .use(BundleTracker, [{filename: './webpack-stats.json'}])

    config.output
        .filename('bundle.js')

    config.optimization
        .splitChunks(false)

    config.resolve.alias
        .set('__STATIC__', 'static')

    config.devServer
        // the first 3 lines of the following code have been added to the configuration
        .public('http://127.0.0.1:8080')    
        .host('127.0.0.1')    
        .port(8080)
        .hotOnly(true)
        .watchOptions({poll: 1000})
        .https(false)
        .disableHostCheck(true)
        .headers({"Access-Control-Allow-Origin": ["\*"]})

},
};

文件 webpack-stats.json 是这样的:

{"status":"done","publicPath":"http://0.0.0.0:8080/","chunks":{"app":[{"name":"bundle.js","publicPath":"http://0.0.0.0:8080/bundle.js","path":"/home/me/myproject/frontend/dist/bundle.js"}]}}

关于如何为 quasar.conf.js 翻译这个的任何提示?

4

1 回答 1

1

在构建键里面放这一行

build: {
  vueRouterMode: 'hash', // available values: 'hash', 'history'
  chainWebpack: config => {
    config
      .output
      .publicPath('http://localhost:8080/')
    config
      .plugin('BundleTracker')
      .use(BundleTracker, [{ filename: './webpack-stats.json' }])

    config.output
      .filename('bundle.js')

    config.optimization
      .splitChunks(false)

    config.resolve.alias
      .set('__STATIC__', 'static')

    config.devServer
      .public('http://127.0.0.1:8080')
      .host('127.0.0.1')
      .port(8080)
      .hotOnly(true)
      .watchOptions({ poll: 1000 })
      .https(false)
      .disableHostCheck(true)
      .headers({ "Access-Control-Allow-Origin": ["\*"] })
  },
}

对于 in devServer 键添加此行

headers: {
    'Access-Control-Allow-Origin':  '*'
}
于 2021-07-16T00:17:14.780 回答