Skip to content

Is there a way to minify a file WITHIN a local module? #26944

Closed Answered by YuLogun
YuLogun asked this question in Questions
Discussion options

You must be logged in to vote

I ended up with esbuild approach

export default defineNuxtModule({
  setup (options, nuxt) {
       nuxt.hook('nitro:config', async (config) => {
           config.virtual = config.virtual || {}
           let script = ''

           try {
               const resolver = createResolver(import.meta.url)
               const scriptPath = await resolver.resolve('../helpers/visual-settings.js')
               const scriptText = await fsp.readFile(scriptPath, 'utf-8')
               const scriptTransformed = await esbuild.transform(scriptText, {
                   minify: true,
                   format: 'iife',
                   target: 'es2020'
               })
               script = scri…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuLogun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants