Skip to content

Commit

Permalink
feat(plugin-vue): respect css.devSourcemap option
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Mar 26, 2022
1 parent bdb9205 commit 65607c5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/playground/vue-sourcemap/vite.config.js
Expand Up @@ -5,6 +5,7 @@ const vuePlugin = require('@vitejs/plugin-vue')
*/
module.exports = {
css: {
devSourcemap: true,
preprocessorOptions: {
less: {
additionalData: '@color: red;'
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-vue/src/index.ts
Expand Up @@ -63,6 +63,7 @@ export interface ResolvedOptions extends Options {
compiler: typeof _compiler
root: string
sourceMap: boolean
cssDevSourcemap: boolean
devServer?: ViteDevServer
devToolsEnabled?: boolean
}
Expand Down Expand Up @@ -99,6 +100,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
reactivityTransform,
root: process.cwd(),
sourceMap: true,
cssDevSourcemap: false,
devToolsEnabled: process.env.NODE_ENV !== 'production'
}

Expand Down Expand Up @@ -137,6 +139,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
...options,
root: config.root,
sourceMap: config.command === 'build' ? !!config.build.sourcemap : true,
cssDevSourcemap: config.css?.devSourcemap ?? false,
isProduction: config.isProduction,
devToolsEnabled:
!!config.define!.__VUE_PROD_DEVTOOLS__ || !config.isProduction
Expand Down
18 changes: 11 additions & 7 deletions packages/plugin-vue/src/style.ts
Expand Up @@ -23,13 +23,17 @@ export async function transformStyle(
isProd: options.isProduction,
source: code,
scoped: block.scoped,
postcssOptions: {
map: {
from: filename,
inline: false,
annotation: false
}
}
...(options.cssDevSourcemap
? {
postcssOptions: {
map: {
from: filename,
inline: false,
annotation: false
}
}
}
: {})
})

if (result.errors.length) {
Expand Down

0 comments on commit 65607c5

Please sign in to comment.