假设我写了一个组件a.vue
,在打包了webpack之后,一些使用了a.vue
的HTML是这样的:
......
<script src="page.js"></script>
<link href="page.css" rel="stylesheet"/>
......
a.Vue
中的JS和CSS被打包到page.js
和page.css
中.I想知道如何将JS和CSS提取到单独的files.Then HTML中:
<script src="a.js"></script>
<script src="page.js"></script>
<link href="a.css" rel="stylesheet"/>
<link href="page.css" rel="stylesheet"/>
我知道这样做不好,我只是想知道怎么做。
发布于 2020-06-29 16:36:51
我在github上发现了一个类似的问题。也许您可以尝试给定的解决方案
https://github.com/vuejs/vue-loader/issues/681
configure webpack.prod.conf.js
config.entry = {}
config.entry[one.name] = one.path
config.output.libraryTarget = 'umd'
config.output.library = `${namespace}${one.importName}`
config.output.filename = `index.min.js`
config.output.path = path.resolve(__dirname, `../dist/components/${one.name}/`)
它是用
webpack(config, function (err, stats) {})
发布于 2020-06-29 16:49:16
就我个人而言,我喜欢单文件组件(SFC),但用Vue分离html、css和js确实很容易。
MyComponent.vue
<template>
// html
</template>
<script src="./MyComponent.js"></script>
<style scoped src="./MyComponent.css">
</style>
发布于 2020-11-05 16:17:09
使用vue-cli
创建项目,然后它可以自动提取css和js。
我正在检查它的webpack配置
https://stackoverflow.com/questions/62633150
复制相似问题