Git Product home page Git Product logo

webpack-to-vite's Introduction

English | 简体中文

Test npm

Webpack to Vite

convert a webpack project to a vite project.
It has been offically included, detail

Quick Start

Use it directly with npx:

$ npx @originjs/webpack-to-vite <project path>

...or install it globally:

$ npm install @originjs/webpack-to-vite -g
$ webpack-to-vite <project path>

The converted Vite project could be found in a new directory filename-toVite.

Note: the default conversion is vue-cli project. Pass in the -t webpack option to convert a webpack project.

Options

The CLI provides the following options:

$ webpack-to-vite --help
  
Usage: webpack-to-vite [options] [root]

Options:
  -v, --version            display version number
  -d --rootDir <path>      the directory of project to be converted
  -t --projectType <type>  the type of the project, use vue-cli or webpack (default: vue-cli)
  -e --entry <type>        entrance of the entire build process, webpack or vite will start from those   
                           entry files to build, if no entry file is specified, src/main.ts or
                           src/main.js will be used as default
  -c --cover               transformed project files will cover the raw files
  -h, --help               display help for command

Awesome projects successfully converted

The following is a list of projects that successfully converted from a webpack project to a vite project using the tool

demos

vue-cli

webpack

Conversion items

The following is a list of configuration items that need to convert

Legend of annotations:

Mark Description
auto convert by webpack-to-vite
⚠️ need manual convert
not support now

Base conversion

  • ✅ B01: add necessary devDependencies and dependencies in package.json
    • necessary: vite-plugin-env-compatible, vite-plugin-html, vite,
    • necessary for Vue2: vite-plugin-vue2
    • necessary for Vue3: @vue/compiler-sfc, @vitejs/plugin-vue, @vitejs/plugin-vue-jsx
  • ✅ B02: add vite's entry file index.html to root directory
    • multiple entries defined by the pages option in vue.config.js is supported
    • please add entry point like <script type="module" src="/src/main.js"></script>. There's no need to add dev-client entry point cause vite supports HMR by default
  • ✅ B03: add vite's config file vite.config.js to root directory
  • ✅ B04: import and use necessary plugins in vite.config.js
    • necessary: vite-plugin-env-compatible
    • necessary for Vue2: vite-plugin-vue2, we set { jsx: true } option to enable jsx support by default
    • necessary for Vue3: @vitejs/plugin-vue, @vitejs/plugin-vue-jsx
  • ✅ B05: imports that omit .vue extension is supported
  • ✅ B06: sass is supported
    • if node-sass is used in dependency, then we'll convert it to sass to dependencies
  • ✅ B07: postcss 8 is supported
    • if postcss 8 is used, then we'll add postcss to dependencies
  • ⚠️ B08: fix issue 'No matching export for import typescript interface'
    • Do not re-export typescript type or interface in vite. You can just export it in file A and import it in file B. Don't try to export it in file B again. The following error may occur if a type or a interface is re-exported:
    Uncaught SyntaxError: The requested module '/src/app/reducers/state.ts' does not provide an export named 'RootState'
    
    • Just remove all re-export types or interfaces in typescript project and modify corresponding imports
  • ⚠️ B09: remove Hot Module Replacement(aka HMR) related code because vite supports HMR by default.
    • The following error may occur when project contains HMR relate code:
    index.tsx:6 Uncaught ReferenceError: module is not defined
      at index.tsx:6
    
  • ⚠️ B10: CSS Modules
    • In vite, any CSS files ending with .module.css is considered a CSS modules file
    • That means you need to covert files with extension of .css to files with extension of .module.css to implement CSS Modules
  • ✅ B11: html-webpack-plugin is supported
    • Options will be applied to plugin vite-plugin-html
    • Variables injected to index.html will be transformed. for example, <%= htmlWebpackPlugin.options.title %> -> <%= title %>
    • Import createHtmlPlugin from html-webpack-plugin and use it like this:
    plugins: [
      createHtmlPlugin({
        inject: {
          data: {
            title: value,
          },
        },
        minify: {
          minifyCss: true
        }
      })
    ]
  • ⚠️ B12: specified Vite plugins
    • You need to import specified Vite plugins based on your project, when this tool can not identify and import them.
    • For example, if windi.css was used before, you should check if Vite has supported it, and then import related plugin (vite-plugin-windicss) manually refered to its plugin guide.

Vue-CLI conversion

Vue-CLI conversion is based on vue.config.js. Configurations will be transformed and written to vite.config.js

  • ✅ V01: base public path

    • process.env.PUBLIC_URL or publicPath or baseUrl -> base
  • ✅ V02: css options

    • css.loaderOptions -> css.preprocessorOptions
    • css.loaderOptions.less.lessOptions.modifyVars -> css.preprocessorOptions.less.modifyVars
    • The sass configuration will influence both sass and scss in Vue-CLI, but in vite we need to configure them respectively. So with only css.loaderOptions.sass option is set in Vue-CLI, it will be converted to css.preprocessorOptions.sass and css.preprocessorOptions.scss. On the other hand, with only css.loaderOptions.scss option is set in Vue-CLI, it will be converted to css.preprocessorOptions.scss.
  • ✅ V03: server options

    • server.strictPort = false is set by default
    • process.env.PORT or devServer.port -> server.port
    • process.env.DEV_HOST or devServer.public or devServer.host -> server.host, and convert http:// or https:// to ''
    • devServer.open, devServer.https -> server.open, server.https
    • if devServer.proxy -> server.proxy is transformed in proxy configuration, we'll also pathRewrite -> rewrite
  • ✅ V04: build options

    • outputDir -> build.outDir
    • css.extract -> build.cssCodeSplit
    • if process.env.MODERN === 'true' is set, we'll also set build.minify = esbuild
    • process.env.GENERATE_SOURCEMAP === 'true' or vueConfig.productionSourceMap or css.sourceMap -> build.sourcemap
  • ✅ V05: resolve.alias options

    • add alias options by default
    resolve: {
      alias: [
        { find: '/^~/', replacement: ''},
        { find: '@', replacement: path.resolve(__dirname,'src') }
      ]
    }
    • webpack alias options will be converted to match format above
  • ✅ V06: client-side env variables

    • extract variable names in jsp scriptlet tags
    • VUE_APP_VARIABLE -> process.env['VUE_APP_VARIABLE']
  • ✅ V07: css automatic imports

    • if 'style-resources-loader' is used to load css preprocessor resources, which is pluginOptions['style-resources-loader']. Configurations will be transformed and written to css.preprocessorOptions
    pluginOptions: {
      'style-resources-loader': {
        preProcessor: 'less',
        patterns: [
          resolve('src/styles/var.less'),
          resolve('src/styles/mixin.less')
        ]
      }
    }

    ->

    css: {
      preprocessorOptions: {
        less: {
          additionalData: `@import "src/styles/var.less";@import "src/styles/mixin.less";`
        }
      }
    }
  • ✅ V08: transform functional webpack config

    • The webpackConfigure and chainWebpack options could be defined as object or function in vue.config.js module
    • To avoid calling error when they were functional, we initialize config options and generate a temporary file (vue.temp.config.js) to reconfig html-webpack-plugin

Webpack conversion

Webpack conversion is based on webpack.config.js or webpack.base.js/webpack.dev.js/webpack.prod.js or webpack.build.js/webpack.production.js, map configuration to vite.config.js

Note: if you are not using configuration files above, you need to convert configurations manually

  • ✅ W01: build entry options
    • if entry is string type: entry -> build.rollupOptions.input
    • if entry is object type: the properties of entry will be converted set to build.rollupOptions.input
    • if entry is function type: execute result of entry will be set to build.rollupOptions.input
  • ✅ W02: output options
    • output.path -> build.outDir
    • output.filename -> build.rollupOptions.output.entryFileNames
    • output.chunkFilename -> build.rollupOptions.output.chunkFileNames
  • ✅ W03: resolve.alias options
    • add alias options by default
    resolve: {
      alias: [
        { find: '@', replacement: path.resolve(__dirname,'src') }
      ]
    }
    • webpack alias options will also be converted to match the configuration above
    • for resolve.alias configurations trailing with $, we'll remove the trailing '$' and set an accurate value
  • ✅ W04: server options
    • devServer.host, devServer.port, devServer.proxy, devServer.https, devServer.contentBase -> server.host, server.port, server.proxy, server.https, server.base
  • ✅ W05: define options
    • new webpack.DefinePlugin() -> define

Others

  • ⚠️ O01: for CommonJS syntax, e.g. require('./')
    • you can use vite plugin @originjs/vite-plugin-commonjs, see also here. Please note that the plugin only supports part of CommonJS syntax. That means some syntax is not supported. You need to covert them to ES Modules syntax manually
    • convert dynamic require(e.g. require('@assets/images/' + options.src)), you can refer to the following steps
    1. use Web API new URL
    <template>
    <img alt="" :src="imgSrc" />
    </template>
    <script>
    export default {
    name: 'img',
    data: () => ({
      imgSrc: new URL('./assets/logo.png', import.meta.url).href
    })
    }
    </script>
    ...or use Vite's API import.meta.glob
    1. create a Model to save the imported modules, use async methods to dynamically import the modules and update them to the Model
    // src/store/index.js
    import Vue from 'vue'
    import Vuex from 'vuex'
    const assets = import.meta.glob('../assets/**')
    Vue.use(Vuex)
    export default new Vuex.Store({
      state: {
        assets: {}
      },
      mutations: {
        setAssets(state, data) {
          state.assets = Object.assign({}, state.assets, data)
        }
      },
      actions: {
        async getAssets({ commit }, url) {
          const getAsset = assets[url]
          if (!getAsset) {
            commit('setAssets', { [url]: ''})
          } else {
            const asset = await getAsset()
            commit('setAssets', { [url]: asset.default })
          }
        }
      }
    })
    1. use in .vue SFC
    // img1.vue
    <template>
      <img :src="$store.state.assets['../assets/images/' + options.src]" />
    </template>
    <script>
    export default {
      name: "img1",
      props: {
        options: Object
      },
      watch: {
        'options.src': {
          handler (val) {
            this.$store.dispatch('getAssets', `../assets/images/${val}`)
          },
          immediate: true,
          deep: true
        }
      }
    }
    </script>
  • ❌ O02: for Element-UI, see also here
     [vite] Uncaught TypeError: Cannot read property '$isServer' of undefined
      at node_modules/[email protected]@element-ui/lib/utils/dom.js (:8080/node_modules/.vite/element-ui.js?v=675d2c77:1189)
      at __require (:8080/node_modules/.vite/chunk-6VNJZP5B.js?v=675d2c77:12)
      at node_modules/[email protected]@element-ui/lib/utils/popup/popup-manager.js (:8080/node_modules/.vite/element-ui.js?v=675d2c77:1478)
      at __require (:8080/node_modules/.vite/chunk-6VNJZP5B.js?v=675d2c77:12)
      at node_modules/[email protected]@element-ui/lib/utils/popup/index.js (:8080/node_modules/.vite/element-ui.js?v=675d2c77:1701)
      at __require (:8080/node_modules/.vite/chunk-6VNJZP5B.js?v=675d2c77:12)
      at node_modules/[email protected]@element-ui/lib/utils/vue-popper.js (:8080/node_modules/.vite/element-ui.js?v=675d2c77:2546)
      at __require (:8080/node_modules/.vite/chunk-6VNJZP5B.js?v=675d2c77:12)
      at Object.5 (:8080/node_modules/.vite/element-ui.js?v=675d2c77:6861)
      at __webpack_require__ (:8080/node_modules/.vite/element-ui.js?v=675d2c77:6547)
    
  • ⚠️ O03: imports that containing multiple alias like: @import '~@/styles/global.scss', which includes alias ~ and @ at the same time
    • you can add an alias { find: /^~@/, replacement: path.resolve(__dirname, 'src') } to resolve.alias options, and place it as the first alias configuration
  • ⚠️ O04: for jsx syntax in .vue file
    • you need to enable jsx support : In Vue2, add plugin vite-plugin-vue2 and set { jsx: true } option. In Vue3, add plugin @vitejs/plugin-vue-jsx
    • you also need to add attribute lang="jsx" to script label if jsx syntax is used, e.g. <script lang="jsx"></script>
    • If you encountered the following error
    3:54:29 PM [vite] Internal server error: /Users/Chieffo/Documents/project/Vue-mmPlayer/src/base/mm-icon/mm-icon.vue?vue&type=script&lang.tsx: Duplicate declaration "h" (This is an error on an internal node. Probably an internal error.)
    Plugin: vite-plugin-vue2
    File: /Users/Chieffo/Documents/project/Vue-mmPlayer/src/base/mm-icon/mm-icon.vue?vue&type=script&lang.tsx
        at File.buildCodeFrameError (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/core/lib/transformation/file/file.js:244:12)
        at Scope.checkBlockScopedCollisions (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/scope/index.js:421:22)
        at Scope.registerBinding (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/scope/index.js:581:16)
        at Scope.registerDeclaration (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/scope/index.js:523:14)
        at Object.BlockScoped (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/scope/index.js:240:12)
        at Object.newFn (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/visitors.js:212:17)
        at NodePath._call (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/path/context.js:53:20)
        at NodePath.call (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/path/context.js:36:14)
        at NodePath.visit (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/path/context.js:90:31)
        at TraversalContext.visitQueue (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/context.js:99:16)
        at TraversalContext.visitMultiple (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/context.js:68:17)
        at TraversalContext.visit (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/context.js:125:19)
        at Function.traverse.node (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/index.js:76:17)
        at NodePath.visit (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/path/context.js:97:18)
        at TraversalContext.visitQueue (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/context.js:99:16)
        at TraversalContext.visitSingle (/Users/Chieffo/Documents/project/Vue-mmPlayer/node_modules/@babel/traverse/lib/context.js:73:19)
    
    you can try to update configuration of babel.config.js like this :
    module.exports = {
      presets: [
        '@vue/app'
      ]
    }
    ->
    module.exports = {
      presets: [
        ['@vue/babel-preset-jsx']
      ]
    }
    see also here
  • ⚠️ O05: for webpack syntax require.context
    • add vite plugin @originjs/vite-plugin-require-context, see also here
  • ✅ O06: we have fixed the error Compiling error when the template of the .vue file has the attribute lang="html"
    • we will remove lang="html" attribute from template label by default, see also here
  • ❌ O07: webpack syntax require.ensure is not supported
  • ⚠️ O08: you need to convert dynamic imports that include alias to absolute paths or relative paths like the followings, see also here
    () => import('@/components/views/test.vue')
    ->
    () => import('./components/views/test.vue')
  • ⚠️ O09: if you encountered build error [rollup-plugin-dynamic-import-variables] Unexpected token, you need to remove empty attr srcset or srcset="" in <img> label.
  • ⚠️ O10: Vite can't resolve some static asset, e.g. .PNG, you can put it in assetsInclude option like assetsInclude: ['**.PNG']
  • ⚠️ O11: support .md markdown file as vue component, you need to add vite-plugin-md plugin.
  • ⚠️ O12: The error Uncaught ReferenceError: global is not defined, see also here
    • For reference, if you only need to shim global, you can add <script>window.global = window;</script> to your index.html

  • ⚠️ O13: Support load SVG files as Vue components
    • ... or when the following error is encountered
    Uncaught (in promise) DOMException: Failed to execute 'createElement' on 'Document': The tag name provided ('/@fs/D:/project/example/node_modules/@example/example.svg') is not a valid name.
    
  • ⚠️ O14: Fix the following errors
    [Vue warn]: Component provided template option but runtime compilation is not supported in this build of Vue. Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".
    
    • you need to set the alias as follows
    resolve: {
      alias: [
        { find: 'vue', replacement: 'vue/dist/vue.esm-bundler.js' }
      ]
    }
  • ⚠️ O15: You may need to install the vite-plugin-optimize-persist plugin for the following reasons

    Vite's dependencies pre-optimization is cool and can improve the DX a lot. While Vite can smartly detect dynamic dependencies, it's on-demanded natural sometimes make the booting up for complex project quite slow.

    [vite] new dependencies found: @material-ui/icons/Dehaze, @material-ui/core/Box, @material-ui/core/Checkbox, updating...
    [vite] ✨ dependencies updated, reloading page...
    [vite] new dependencies found: @material-ui/core/Dialog, @material-ui/core/DialogActions, updating...
    [vite] ✨ dependencies updated, reloading page...
    [vite] new dependencies found: @material-ui/core/Accordion, @material-ui/core/AccordionSummary, updating...
    [vite] ✨ dependencies updated, reloading page...
    

webpack-to-vite's People

Contributors

chieffo2021 avatar chinanf-boy avatar dovahkiin1225 avatar flyfishzy avatar jiawulin001 avatar konpeki622 avatar llin6025 avatar peteralfredlee avatar wangsongc avatar ygj6 avatar yjzqv avatar yosion-p avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

webpack-to-vite's Issues

How to resolve vue extension in node_modules?

Describe the question

Vite have provided resolve.extensions to omit the extensions for imports:

{
  resolve: {
    extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'] // .vue added
  }
}

It works for project code but not packages in node_modules. I have searched for Google and no solutions found, so I am seeking for help in such this community.

Add `vite dev` to scripts

Is your feature request related to a problem? Please describe.

After migratioin three vite scripts are aded to package-json

"serve-vite": "vite",
"build-vite": "vite build",
"preview-vite": "vite preview"

a call to vite dev is missing.

Describe the solution you'd like

Pleasa also include

"dev-vite": "vite dev",

I ran several migartions and always had to add this line.

"Command not found" and "Missing semicolon"

Versions

  • webpack-to-vite: 1.0.1
  • node: 17.1.0

Reproduction

GitHub repository at this commit: snikproject/quiz@60ea114

Steps to reproduce

$ npx @originjs/webpack-to-vite -t webpack .
sh: line 1: webpack-to-vite: command not found
$ sudo npm install @originjs/webpack-to-vite -g
$ webpack-to-vite -t webpack .
******************* Webpack to Vite *******************
Project path: .
progress [██████████████████░░░░░░░░░░░░░░░░░░░░░░] 44% | AST Parsing: /home/konrad/projekte/snik/snik-quiz/src/componSyntaxError: Missing semicolon. (1:63)
    at Object._raise (/usr/lib/node_modules/@originjs/webpack-to-vite/node_modules/@babel/parser/lib/index.js:541:17)
    at Object.raiseWithData (/usr/lib/node_modules/@originjs/webpack-to-vite/node_modules/@babel/parser/lib/index.js:534:17)
    at Object.raise (/usr/lib/node_modules/@originjs/webpack-to-vite/node_modules/@babel/parser/lib/index.js:495:17)
    at Object.semicolon (/usr/lib/node_modules/@originjs/webpack-to-vite/node_modules/@babel/parser/lib/index.js:3550:10)
    at Object.parseExpressionStatement (/usr/lib/node_modules/@originjs/webpack-to-vite/node_modules/@babel/parser/lib/index.js:13899:10)
    at Object.parseStatementContent (/usr/lib/node_modules/@originjs/webpack-to-vite/node_modules/@babel/parser/lib/index.js:13490:19)
    at Object.parseStatement (/usr/lib/node_modules/@originjs/webpack-to-vite/node_modules/@babel/parser/lib/index.js:13352:17)
    at Object.parseLabeledStatement (/usr/lib/node_modules/@originjs/webpack-to-vite/node_modules/@babel/parser/lib/index.js:13891:22)
    at Object.parseStatementContent (/usr/lib/node_modules/@originjs/webpack-to-vite/node_modules/@babel/parser/lib/index.js:13488:19)
    at Object.parseStatement (/usr/lib/node_modules/@originjs/webpack-to-vite/node_modules/@babel/parser/lib/index.js:13352:17) {
  loc: Position { line: 1, column: 63 },
  pos: 63,
  code: 'BABEL_PARSER_SYNTAX_ERROR',
  reasonCode: 'MissingSemicolon'
}
Conversion failed.

What is Expected?

  • it should work with npx
  • it should transform my project

What is actually happening?

  • it does not work with npx
  • it fails because of a missing semicolon in the originjs code (?)

Failed to resolve vue/compiler-sfc

Versions

  • webpack-to-vite: v1.0.6
  • node: v14.16.0

Reproduction

https://github.com/gothinkster/vue-realworld-example-app

Additional Details

Steps to reproduce

After successfully converting the repo, execute npm run serve-vite

What is Expected?

start serve

What is actually happening?

$ vite
error when starting dev server:                                                                                                       
Error: Failed to resolve vue/compiler-sfc.                                                                                            
@vitejs/plugin-vue requires vue (>=3.2.13) or @vue/compiler-sfc to be present in the dependency tree.                                 
    at resolveCompiler (D:\project\github-project\newbee-mall-vue3-app\node_modules\@vitejs\plugin-vue\dist\index.js:4069:11)         
    at Object.configResolved (D:\project\github-project\newbee-mall-vue3-app\node_modules\@vitejs\plugin-vue\dist\index.js:4768:39)   
    at D:\project\github-project\newbee-mall-vue3-app\node_modules\vite\dist\node\chunks\dep-f5552faa.js:74824:127                    
    at Array.map (<anonymous>)                                                                                                        
    at resolveConfig (D:\project\github-project\newbee-mall-vue3-app\node_modules\vite\dist\node\chunks\dep-f5552faa.js:74824:35)     
    at processTicksAndRejections (node:internal/process/task_queues:96:5)                                                             
    at async createServer (D:\project\github-project\newbee-mall-vue3-app\node_modules\vite\dist\node\chunks\dep-f5552faa.js:60326:20)
    at async CAC.<anonymous> (D:\project\github-project\newbee-mall-vue3-app\node_modules\vite\dist\node\cli.js:688:24)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Make sure dependencies have been installed before conversion

Is your feature request related to a problem? Please describe.

Sometimes it prints Failed to parse vue config from default file path although the vue.config.js file exists. There is an error during importing because module was not found.

Describe the solution you'd like

Print info telling user to install dependencies before conversion.

Describe alternatives you've considered

Add print information.

Additional context

None.

Support React in the future ?

Hi all!
Firstly, thanks for your helpful tool
Do you have the plan to support React(Create react app) in the future?

使用webpack-to-vite转vue-cli的vue3 demo项目日志有报错

Versions

  • webpack-to-vite: v1.1.1
  • node: v16.14.2
  • @vue/cli: v5.0.4

Reproduction

Additional Details

Steps to reproduce

  1. vue create hello-origin
  2. choose the first one(Vue3)
  3. webpack-to-vite hello-origin

What is Expected?

No console error

What is actually happening?

error

Conversion of html generated by html-webpack-plugin

Is your feature request related to a problem? Please describe.

html-webpack-plugin is a common webpack plugin that simplifies creation of HTML files to serve your webpack bundles. It can generate an HTML file, for example, use variables by writing template tags <%= htmlWebpackPlugin.options.data %> in the html file. But this plugin doesn't work if we converted the webpack project to Vite with this tools.

Describe the solution you'd like

After conversion, It works well on Vite without manully changing.

Describe alternatives you've considered

Import vite-plugin-html and apply webpack plugin options to it.

Additional context

Options to convert:

  • title
  • template
  • filename
  • inject
  • favicon
  • minify
  • hash
  • chunks
  • xhtml
  • publicPath
  • templateContent
  • templateParameter

Configuration for entry filename and chunk filename

Is your feature request related to a problem? Please describe.

There is no transformer for entry filename and chunk filename, which is always used in webpack configuration.

Describe the solution you'd like

After converting, the entry filename and chunk filename could be configured in vite.config.js.

Describe alternatives you've considered

  • output.filename -> build.rollupOptions.output.entryFileNames
  • output.chunkFilename -> build.rollupOptions.output.chunkFileNames

Additional context

I added it in PR #86 . But it is ineffective when the filename was configured with environment variables.

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.