1.用vue-cli建構專案時,需要引入本地的靜態js和CSS文件,直接npm run bulid打包後的文件沒辦法連JS和CSS一直打包,需要怎麼配webpack或用gulp才能打包?
相關程式碼如下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ETA</title>
<meta name="viewport"
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
<link rel="stylesheet" type="text/css" href="static/css/reset.css">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="static/img/favicon.ico" rel="icon" type="image/x-icon" />
<link rel="stylesheet" href="static/assets/animate/animate.min.css">
<link rel="stylesheet" href="static/assets/styles/summernote-bs3.css">
<link rel="stylesheet" href="static/assets/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="static/assets/styles/app.css">
<link rel="stylesheet" href="static/css/after.css">
</head>
<body>
<p id="app"></p>
<!-- built files will be auto injected -->
<!-- jQuery -->
<script src="//cdn.bootcss.com/jquery/3.2.0/jquery.js"></script>
<!-- Bootstrap -->
<script src="//cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="static/scripts/tether.min.js"></script>
<!-- code -->
<script src="static/scripts/jquery.storageapi.min.js"></script>
<script src="static/scripts/pace.min.js"></script>
<script src="static/scripts/config.lazyload.js"></script>
<script src="static/scripts/palette.js"></script>
<script src="static/scripts/ui-load.js"></script>
<script src="static/scripts/ui-jp.js"></script>
<script src="static/scripts/ui-include.js"></script>
<script src="static/scripts/ui-device.js"></script>
<script src="static/scripts/ui-nav.js"></script>
<script src="static/scripts/ui-toggle-class.js"></script>
</body>
</html>
其中js檔案既包含本地靜態的也包含外部cdn引入的檔案
求打包路子
ringa_lee2017-05-19 10:44:04
會自動打包的,只是本地靜態js 要放在專案工程的資料夾中,否則打包不進來的,我一般是在專案中會新建一個js資料夾,然後把所有靜態JS 都放在裡面
天蓬老师2017-05-19 10:44:04
你如果想要用本地js或css文件,需要到main.js裡面去分別import 他們,這樣你的js和css程式碼就會被打包進項目,而不是在index.html裡面去引用本地js和css 。當然,cdn加速的外部文件是可以在index.html裡面引用的