【发布时间】:2020-05-16 11:44:11
【问题描述】:
我正在使用 vue cli ui 来设置 chrome 扩展样板。我已经安装了 axios 和 bootstrap,我想在扩展中使用它们。我注意到当我运行构建过程时,引导程序不会与扩展程序捆绑在一起,我无法使用它的类和网格来设计我的 chrome 扩展程序的 UI。我有这一行来在主 vue 组件中导入引导程序,这是 webpack 配置文件。有没有办法解决这个依赖问题?
App.vue:
<template>
<div class="container p-0">
<div class="row m-0">
<div class="col-12">
<div class="input-group">
<input type="text" class="form-control" v-model="Profile" placeholder="@username">
<div class="input-group-append">
<button class="btn btn-outline-secondary" v-on:click.prevent="showFeed()">Load profile</button>
</div>
</div>
</div>
<div class="col-4" v-if="Feed">
</div>
</div>
</div>
</template>
<script>
import jquery from 'jquery';
import bootstrap from 'bootstrap';
import axios from 'axios';
export default {
name: 'app',
data() {
return {
Profile: {
Type: String,
default() {
return null;
}
},
Feed: null
}
},
methods: {
showFeed() {
console.log('clicked!')
}
}
}
</script>
<style>
.main_app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
webpack 配置文件:
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");
// Generate pages object
const pagesObj = {};
const chromeName = [
"popup",
];
chromeName.forEach(name => {
pagesObj[name] = {
entry: `src/${name}/index.js`,
template: "public/index.html",
filename: `${name}.html`
};
});
const manifest =
process.env.NODE_ENV === "production" ? {
from: path.resolve("src/manifest.production.json"),
to: `${path.resolve("dist")}/manifest.json`
} : {
from: path.resolve("src/manifest.development.json"),
to: `${path.resolve("dist")}/manifest.json`
};
const plugins = [
CopyWebpackPlugin([manifest])
]
plugins.push(
CopyWebpackPlugin([{
from: path.resolve(`src/locales/en/messages.json`),
to: path.resolve(`dist/_locales/en/messages.json`)
}])
)
plugins.push(
CopyWebpackPlugin([{
from: path.resolve(`src/locales/zh_CN/messages.json`),
to: path.resolve(`dist/_locales/zh_CN/messages.json`)
}])
)
plugins.push(
CopyWebpackPlugin([{
from: path.resolve(`node_modules/bootstrap/dist/css/bootstrap.min.css`),
to: path.resolve(`dist/css/bootstrap.min.css`)
}])
)
module.exports = {
pages: pagesObj,
productionSourceMap: false,
configureWebpack: {
plugins: plugins,
},
chainWebpack: config => {
if (process.env.npm_config_report) {
config
.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
}
}
};
【问题讨论】:
标签: javascript html css webpack