当前位置: 首页 > news >正文

网店网站开发郑州网站建设公司排行榜

网店网站开发,郑州网站建设公司排行榜,m开头的可以做网站的软件,上饶市建设局培训网站先看看我的目录结构(我全局使用TS): 一、安装配置webpack打包 安装esno npm install esnoesno 是基于 esbuild 的 TS/ESNext node 运行时,有了它,就可以直接通过esno *.ts的方式启动脚本,package.json中添加 type:…

先看看我的目录结构(我全局使用TS):
在这里插入图片描述

一、安装配置webpack打包

安装esno

npm install esno

esno 是基于 esbuild 的 TS/ESNext node 运行时,有了它,就可以直接通过esno *.ts的方式启动脚本,package.json中添加 type:“module”,使用esm的模块管理方式。

{"name": "create-my-vue-test","version": "1.0.0","main": "index.js","scripts": {"test": "echo \"Error: no test specified\" && exit 1","build": "esno ./config/build.ts"},"type": "module","keywords": [],"author": "","license": "ISC","description": "","dependencies": {"esno": "^4.0.0"}
}

创建build.ts,执行npm run build
在这里插入图片描述

安装webpack、webpack-cli

npm install webpack
npm install webpack-cli

webpack必须安装webpackcli
build.ts中编写打包代码

import webpack, { Stats } from "webpack";
import config from "./webpack.config"//我直接使用webpack,不使用webpck-cli,vue的脚手架
const compiler = webpack(config, (err, stats) => {if (err) {console.error(err.stack || err)} else if ((stats as Stats).hasErrors()) {console.log(stats);} else {}
})

编写打包配置文件webpack.config.ts

import path from "path";//nodejs里面的基本包,用来处理路径
const parentDir = path.resolve(process.cwd());//我们先打个基本的包
export default {mode: "development" as "development",entry: "./src/main.ts",output: {path: path.join(parentDir, 'dist'),filename: "bundle.js",},module: {// 指定要加载的规则rules: [],},// 模块配置:让webpack了解哪些方法可以被当作模块引入resolve: {extensions: ['.ts', '.js']},plugins: []
};

创建业务代码入口文件main.ts

let test: string = '';
console.log(test);

执行一下打包npm run build
在这里插入图片描述
报错了,说需要个loader来处理ts,我们安装ts-loader,并在webpack.config.ts中添加相关配置

npm install ts-loader
import path from "path";//nodejs里面的基本包,用来处理路径
const parentDir = path.resolve(process.cwd());//我们先打个基本的包
export default {mode: "development" as "development",entry: "./src/main.ts",output: {path: path.join(parentDir, 'dist'),filename: "bundle.js",},module: {// 指定要加载的规则rules: [{test: /\.ts$/, // 解析 tsloader: "ts-loader"}],},// 模块配置:让webpack了解哪些方法可以被当作模块引入resolve: {extensions: ['.ts', '.js']		},plugins: []
};

再次执行npm run build

在这里插入图片描述
有报错了,说没有tsconfig.json文件
创建tsconfig.ts

{"compilerOptions": {"target": "esnext","module": "esnext","strict": true,"jsx": "preserve","importHelpers": true,"moduleResolution": "node","skipLibCheck": true,"esModuleInterop": true,"allowSyntheticDefaultImports": true,"sourceMap": true,"baseUrl": ".","paths": {"@/*": ["src/*"]},"lib": ["esnext","dom","dom.iterable","scripthost"]},"include": ["src/*.ts","src/**/*.ts","src/**/*.tsx","src/**/*.vue","tests/**/*.ts","tests/**/*.tsx"],"exclude": ["node_modules"]}

再次打包,打包成功了
在这里插入图片描述
手动拷贝到index.html里面试试,运行也没有问题
在这里插入图片描述
在这里插入图片描述
安装HtmlWebpackPlugin自动拷贝打包文件到index.html中,安装CleanWebpackPlugin,自动清除dist目录,并更新webpack.config.ts

import path from "path";//nodejs里面的基本包,用来处理路径
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import HtmlWebpackPlugin from 'html-webpack-plugin';
const parentDir = path.resolve(process.cwd());//我们先打个基本的包
export default {mode: "development" as "development",entry: "./src/main.ts",output: {path: path.join(parentDir, 'dist'),filename: "bundle.js",},module: {// 指定要加载的规则rules: [{test: /\.ts$/, // 解析 tsloader: "ts-loader"}],},// 模块配置:让webpack了解哪些方法可以被当作模块引入resolve: {extensions: ['.ts', '.js']},plugins: [new HtmlWebpackPlugin({title: '你好,世界',template: './public/index.html'}),new CleanWebpackPlugin()]
};

现在就可以自动将打包js文件插入到index.html中
在这里插入图片描述
增加开发服务并热更新,安装webpack-dev-server

npm install webpack-dev-server

创建dev.ts

import path from "path";//nodejs里面的基本包,用来处理路径
import webpack, { Stats } from "webpack";
import WebpackDevServer from "webpack-dev-server";
import config from "./webpack.config"const parentDir = path.resolve(process.cwd());const compiler = webpack(config)const server = new WebpackDevServer({port: 3000,static: {directory: path.join(parentDir, 'public'),},
}, compiler);const runServer = async () => {console.log('Starting server...');await server.start();
};runServer();

在package.json中增加dev的脚本

"scripts": {"build": "esno ./config/build.ts","dev": "esno ./config/dev.ts"},

执行npm run dev,就启动起来了
在这里插入图片描述

二、集成Vue

增加App.vue、更改main.ts、main.scss
App.vue

<template><div>test</div>
</template><script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({name: "App",setup() {return {};},
});
</script>

main.ts

import { createApp } from 'vue'
import App from './components/App.vue'
import "./assets/main.scss"// 注意:这里的 #app,需要在 public/index.html 中,写一个 id 为 app 的 div
createApp(App).mount('#app');

main.scss

* {background-color: red;
}

在这里插入图片描述
安装依赖

npm i --save-dev vue vue-loader url-loader style-loader css-loader node-sass sass-loader

更改webpack.config.ts

import path from "path";//nodejs里面的基本包,用来处理路径
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { VueLoaderPlugin } from "vue-loader"const parentDir = path.resolve(process.cwd());//我们先打个基本的包
export default {mode: "development" as "development",entry: "./src/main.ts",output: {path: path.join(parentDir, 'dist'),filename: "bundle.js",},module: {// 指定要加载的规则rules: [{test: /\.vue$/,loader: 'vue-loader',},{test: /\.scss$/,use: ['style-loader',//https://github.com/vuejs/vue-style-loader/issues/42'css-loader','sass-loader']},{test: /\.css$/i,use: ["style-loader", "css-loader"],},{test: /\.(woff|woff2|eot|ttf|svg)$/,use: [{loader: 'url-loader',options: {limit: 10000,name: './font/[hash].[ext]',publicPath: 'dist'}}]},{test: /\.(png|jpg|gif)$/i,use: [{loader: 'url-loader',options: {limit: 8192,},},],},{test: /\.ts$/, // 解析 tsloader: "ts-loader",options: {// 上面一行不太重要,应该会按照默认路径寻找,下面一行必须要// appendTsSuffixTo/appendTsxSuffixTo配置项的意思是说,从vue文件里面分离的script的ts,tsx(取决于<script lang="xxx"></script>)内容将会被加上ts或者tsx的后缀,然后交由ts-loader解析。// 我在翻看了ts-loader上关于appendTsxSuffixTo的讨论发现,ts-loader貌似对文件后缀名称有很严格的限定,必须得是ts/tsx后缀,所以得在vue-loader extract <script>中内容后,给其加上ts/tsx的后缀名,这样ts-loader才会去处理这部分的内容。// 在Vue项目中使用TypescriptconfigFile: path.resolve(process.cwd(), 'tsconfig.json'),appendTsSuffixTo: [/\.vue$/]},}],},// 模块配置:让webpack了解哪些方法可以被当作模块引入resolve: {extensions: ['.tsx','.ts','.mjs','.js','.jsx','.vue','.json']},plugins: [new HtmlWebpackPlugin({title: '你好,世界',template: './public/index.html'}),new CleanWebpackPlugin(),// make sure to include the plugin for the magicnew VueLoaderPlugin()]
};

创建shims-vue.d.ts

/* eslint-disable */
declare module '*.vue' {import type { DefineComponent } from 'vue'const component: DefineComponent<{}, {}, any>export default component
}

最终的package.json

{"name": "create-my-vue-test","version": "1.0.0","main": "index.js","type": "module","scripts": {"test": "echo \"Error: no test specified\" && exit 1","dev": "esno ./config/dev.ts","build": "esno ./config/build.ts"},"keywords": [],"author": "","license": "ISC","description": "","dependencies": {"clean-webpack-plugin": "^4.0.0","css-loader": "^6.9.1","esno": "^4.0.0","html-webpack-plugin": "^5.6.0","node-sass": "^9.0.0","sass-loader": "^14.0.0","style-loader": "^3.3.4","ts-loader": "^9.5.1","url-loader": "^4.1.1","vue": "^3.4.15","vue-loader": "^17.4.2","webpack": "^5.89.0","webpack-cli": "^5.1.4","webpack-dev-server": "^4.15.1"}
}

再次运行,基础搭建好了
在这里插入图片描述


文章转载自:
http://slack.hkpn.cn
http://sompa.hkpn.cn
http://frey.hkpn.cn
http://pediculate.hkpn.cn
http://underspin.hkpn.cn
http://uppsala.hkpn.cn
http://fontanel.hkpn.cn
http://assonant.hkpn.cn
http://precompose.hkpn.cn
http://anglesmith.hkpn.cn
http://uta.hkpn.cn
http://withdraw.hkpn.cn
http://dendrophagous.hkpn.cn
http://bicuculline.hkpn.cn
http://horsepower.hkpn.cn
http://insurrectionist.hkpn.cn
http://eolian.hkpn.cn
http://chloe.hkpn.cn
http://undated.hkpn.cn
http://triplane.hkpn.cn
http://bookshelves.hkpn.cn
http://sensoria.hkpn.cn
http://relaid.hkpn.cn
http://unaccepted.hkpn.cn
http://loincloth.hkpn.cn
http://pocketful.hkpn.cn
http://skelp.hkpn.cn
http://befringe.hkpn.cn
http://heterogeneous.hkpn.cn
http://ochrea.hkpn.cn
http://ropeyarn.hkpn.cn
http://persist.hkpn.cn
http://hurling.hkpn.cn
http://enterotoxemia.hkpn.cn
http://otalgic.hkpn.cn
http://racemiferous.hkpn.cn
http://finn.hkpn.cn
http://cackle.hkpn.cn
http://mirabilia.hkpn.cn
http://concurrent.hkpn.cn
http://houseplace.hkpn.cn
http://artfully.hkpn.cn
http://tally.hkpn.cn
http://windsurf.hkpn.cn
http://tho.hkpn.cn
http://pannikin.hkpn.cn
http://slimicide.hkpn.cn
http://injunction.hkpn.cn
http://superstitionist.hkpn.cn
http://entertainer.hkpn.cn
http://epimysium.hkpn.cn
http://leishmania.hkpn.cn
http://agrimony.hkpn.cn
http://workmanship.hkpn.cn
http://oebf.hkpn.cn
http://togaed.hkpn.cn
http://radiotechnology.hkpn.cn
http://naris.hkpn.cn
http://affettuoso.hkpn.cn
http://leptophyllous.hkpn.cn
http://coelome.hkpn.cn
http://jactation.hkpn.cn
http://gravitate.hkpn.cn
http://inexactly.hkpn.cn
http://gotcher.hkpn.cn
http://morn.hkpn.cn
http://wirescape.hkpn.cn
http://galatian.hkpn.cn
http://integral.hkpn.cn
http://perispomenon.hkpn.cn
http://childrenese.hkpn.cn
http://unperceivable.hkpn.cn
http://serviceability.hkpn.cn
http://eutrophy.hkpn.cn
http://ferromagnetic.hkpn.cn
http://aeruginous.hkpn.cn
http://transatlantic.hkpn.cn
http://honolulan.hkpn.cn
http://bimana.hkpn.cn
http://caliginous.hkpn.cn
http://vote.hkpn.cn
http://ocker.hkpn.cn
http://barkeep.hkpn.cn
http://chaos.hkpn.cn
http://obsolescent.hkpn.cn
http://fpm.hkpn.cn
http://fidelism.hkpn.cn
http://campshed.hkpn.cn
http://senility.hkpn.cn
http://cardfile.hkpn.cn
http://hangwire.hkpn.cn
http://biogeocenose.hkpn.cn
http://backswordman.hkpn.cn
http://diffusibility.hkpn.cn
http://condensibility.hkpn.cn
http://rockbridgeite.hkpn.cn
http://hypoesthesia.hkpn.cn
http://knackered.hkpn.cn
http://guitarfish.hkpn.cn
http://cineangiography.hkpn.cn
http://www.hrbkazy.com/news/66061.html

相关文章:

  • 网站推广连接怎么做的优化
  • 衡水做wap网站多少钱企业网站怎么注册
  • 微信扫码关注登陆wordpress廊坊网站排名优化公司哪家好
  • 淘宝客做网站备注怎么写的百度免费推广方法
  • 网站一般如何做搜索功能典型的口碑营销案例
  • 网站域名管理中心交换链接营销案例
  • php手机网站怎么做怎么建网页
  • 临沂做进销存网站国外产品推广平台
  • 建设公司网站价格如何做谷歌优化
  • 自适应网站用什么软件设计百度推广多少钱一天
  • 网站和微信公众号建设重庆电子商务网站seo
  • 网站建设业务拓展思路网络最有效的推广方法
  • 果农在哪些网站做推广seowhy教研室
  • 网站会员充值接口怎么做的万网官网域名注册
  • 义乌水务建设集团官方网站南京seo排名优化公司
  • 凡客诚品网站设计网络培训心得体会5篇
  • 做网站需要的素材照片哪里可以学网络运营和推广
  • 南京快速建站模板下载爱站网注册人查询
  • 网站建设十胜石深圳seo培训
  • 台前网站建设价格百度怎么搜索网址打开网页
  • 网站备案一般要多久网站seo价格
  • 上海手机网站建设电话能打开各种网站的搜索引擎
  • 新蔡哪有做网站建设的代发百度关键词排名
  • 教育局两学一做网站seo刷关键词排名软件
  • 做美食网站的目的襄阳seo优化排名
  • 长沙建设企业网站综合型b2b电子商务平台网站
  • 成熟网站开发单位个人如何优化网站有哪些方法
  • 做研学的网站如何做推广呢
  • 如何做网站活动steam交易链接在哪里看
  • 网页版传奇排行seo搜索引擎优化推荐