Giter VIP home page Giter VIP logo

Comments (5)

XiaoLin1995 avatar XiaoLin1995 commented on August 26, 2024

webpak

// webpack.config.js
module.exports = {
  // ...
  module: {
    rules: [
      // ...
      {
        test: /\.ts$/,
        exclude: /node_modules/,
        use: [
          // ...
          {
            loader: 'import-meta-loader',
          }
        ]
      }
    ]
  }
}

vue cli

// vue.config.js
const importMetaLoader = require('import-meta-loader')
const path = require('path')

module.exports = {
  // ...
  chainWebpack: (config) => {
    config.module.rule('ts')
      .test(/\.ts$/)
      .exclude.add(path.resolve('node_modules'))
      .end()
      .use(importMetaLoader)
      .loader('import-meta-loader')
      .options({
        alias: Object.fromEntries(config.resolve.alias.store)
      })
      .end()
  }
}

from vuecli-vite-template.

oui-a11y avatar oui-a11y commented on August 26, 2024

is error, you can test
image

from vuecli-vite-template.

oui-a11y avatar oui-a11y commented on August 26, 2024

this project is vue cli ts demo,you can test

from vuecli-vite-template.

XiaoLin1995 avatar XiaoLin1995 commented on August 26, 2024

vue cli version: 5.0.8

// vue.config.js
const { defineConfig } = require('@vue/cli-service')
const importMetaLoader = require('import-meta-loader')
const path = require('path')

function setTSLoader (config, { use, loader, options }) {
  const tsRule = config.module.rule('ts')
  const tsLoader = tsRule.uses.store.get('ts-loader')
  const tsOtherLoaders = new Map()
  tsRule.uses.store.forEach((val, key) => {
    if (key === 'ts-loader') return
    tsOtherLoaders.set(key, val)
  })
  tsRule.uses.clear()
  tsOtherLoaders.forEach((val, key) => {
    tsRule.uses.store.set(key, val)
  })

  tsRule.test(/\.ts$/)
    .exclude.add(path.resolve('node_modules'))
    .end()
    .use(use)
    .loader(loader)
    .options(options)
    .end()
  
  tsRule.uses.store.set('ts-loader', tsLoader)
}

module.exports = defineConfig({
  transpileDependencies: true,
  chainWebpack: (config) => {
    setTSLoader(
      config,
      {
        use: importMetaLoader,
        loader: 'import-meta-loader',
        options: Object.fromEntries(config.resolve.alias.store)
      }
    )
  }
})

from vuecli-vite-template.

oui-a11y avatar oui-a11y commented on August 26, 2024

Can you take a look at the sample code of the vue cli ts version. self test is error. format path may have problem.
image

from vuecli-vite-template.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.