vuepress: Generated js files have SyntaxError when enabling source map in webpack config
- I confirm that this is a issue rather than a question.
Bug report
When enabling source map in the configureWebpack option, the generated js files have SyntaxErrors. Comment the devtool: "source-map" line solves the problem.
Version
1.0.0-alpha.40
Steps to reproduce
git clone https://github.com/jjyyxx/vuepress-1367-repro.git
cd vuepress-1367-repro
npm run build
What is expected?
Generate valid code.
What is actually happening?
Uncaught SyntaxError: Unexpected token } happens in app.xxx.js.
Other relevant information
- Your OS: Windows 10 1809
- Node.js version: v11.4.0
- Browser version: Google Chrome v72.0.3626.119
- Is this a global or local install? local
- Which package manager did you use for the install? npm
- Does this issue occur when all plugins are disabled? yes
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (12 by maintainers)
@sinchang You misused lambda.
In
It is pretty valid javascript but may not be what you what to achieve. The correct way is
which returns an object and fails as exprected.
I found that the function
workaroundEmptyStyleChunkcaused this problem. https://github.com/vuejs/vuepress/blob/1850be7f343e54575c64d82c4f0cedc25a9aa91c/packages/%40vuepress/core/lib/build.js#L174-L190The hack was introduced to address this issue. This snippet prepends
styleChunkContenttoappChunkContentand writes it back to app.[hash].js. When building chunks without sourcemap, each chunk ends with a semicolon (always?). So the prepending operation generates valid code.BUT, if sourcemap is configured to be generated, webpack will append a comment line to the end of each js chunk, which breaks the precondition of
each chunk ends with a semicolon, leading to invalid code after prepending.