2

I am using koa2 as backend and koa-swig to render my page. Here is the structure: enter image description here

Inside dist file, there are index.html and static. All css, js, and images are in there. And here is the error: image

Here is the build setting in config/index.js of webpack:

build: {
   env: require('./prod.env'),
   index: path.resolve(__dirname, '../dist/index.html'),
   assetsRoot: path.resolve(__dirname, '../dist'),
   assetsSubDirectory: 'static',
   assetsPublicPath: '/',
   productionSourceMap: true,
   productionGzip: false,
   productionGzipExtensions: ['js', 'css'],
   bundleAnalyzerReport: process.env.npm_config_report
   }

2 Answers 2

2

After you build the Vue.js app, your output files will be available in dist/ folder.

From this point onwards, your webpack build config does not matter. What matters is how your server handles the requests.

The contents of dist folder will have the following:

  1. index.html file
  2. static folder

I assume you would copy the above files to your server for end-to-end testing.

Your index.html links to files in your static folder using plain <script> or <link> tags. After your browser fetches the index.html, it will start requesting all the other files like app.xyz.js, vendor.xyz.js, etc. You either need to ensure that these static files are accessible in their default paths, or change path as explained in the below example:

<script type="text/javascript" src="/static/js/app.xyz.js"></script>

may need to be changed to

<script type="text/javascript" src="/static_files/scripts/app.xyz.js"></script>

You need to look at server logs to see why the requests are not getting served. Once you fix the server side errors, then your Vue app will work normally in production mode.

Sign up to request clarification or add additional context in comments.

Comments

1

Just change the config assetsPublicPath: '/' to assetsPublicPath: '../dist', it works for me.

1 Comment

the option is now called publicPath: ''

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.