Vue.js/webpack 不创建构建文件? [英] Vue.js / webpack creates no build file?

查看:28
本文介绍了Vue.js/webpack 不创建构建文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但到底是什么.

This might be a stupid question but what the hell.

我使用的是 vue-cli webpack-simple 模板,在这个项目的 webpack 配置中,我找到了以下内容:

I am using the vue-cli webpack-simple template, in the webpack config of this project I find the following:

output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },

虽然没有文件正在构建.运行 webpack 服务器时,我可以通过浏览器访问该文件.build.js 文件是否只有在 webpack 开发服务器运行时才可用?

No file is being built though. When running the webpack server I can access the file through the browser though. Is the build.js file only available when the webpack development server is running?

这是runtime vs standalone 的定义吗?即使在查看了文档后,我仍然对确切的区别感到困惑.

Is this what defines runtime vs standalone? Even after reviewing the documentation I am still confused what the exact difference is.

我需要一个编译文件,因为我正在尝试发布一个转译文件以将我的包发布到 NPM.

I need a compiled file since I am trying to publish a transpiled file to publish my package to NPM.

干杯.

推荐答案

运行

npm run build

这将创建一个包含 build.js/dist 目录.

That will create a /dist directory that contains build.js.

您可以在 package.json 中查看可运行的脚本.webpack-simple 模板只有 runbuild.您需要复制 index.html 和 dist 文件夹.

You can see the scripts that are available to run in package.json. The webpack-simple template only has run and build. You'll need to copy over the index.html and the dist folder.

当您使用 npm run dev 进行开发时,您正在使用热模块重新加载,并且没有构建 js 是通过热模块服务器提供的临时可用的.

When you are developing using npm run dev you are using hot module reloading and no js is built a temporary one available through the hot module server.

如果你只想构建一个单一的文件组件,你可以使用 vue-cli构建命令.

If you want to build just one single file component you can use the vue-cli's build command.

vue build Component.vue --prod --lib Component

其中 Component 是单个文件组件的名称.这将生成一个仅包含您指定的组件的脚本文件.将该脚本包含在您的 HTML 中,并使用 `Vue.component("component", Component) 在全局范围内公开它.

where Component is the name of the single file component. This will generate a script file containing only the component you specified. Include that script in your HTML and expose it globally using `Vue.component("component", Component).

这篇关于Vue.js/webpack 不创建构建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆