配置webpacknpm i init --y npm i webpack -D npm i webpack-cli -D npm i @types/firefox-webext-browser @types/chrome -D // 瀏覽器擴(kuò)展API提示 支持 Typescripttsc --init npm i typescript ts-loader -D 設(shè)置 { "compilerOptions": { "target": "ES2016", "module": "commonjs", // ts-node 不支持 commonjs 以外的任何模塊語(yǔ)法 "allowJs": true, "outDir": "./dist", "rootDir": "./src", "strict": true, "moduleResolution": "node" }, "exclude": ["node_modules"], "include": ["./src/**/*.ts"] } 讓配置文件支持 npm i ts-node @types/node @types/webpack -D 創(chuàng)建 import path from "path"; import webpack from "webpack"; const config: webpack.Configuration = { mode: "production", entry: "./src/index.ts", output: { path: path.resolve(__dirname, "dist"), filename: "[name].bundle.js", }, module: { rules: [ { test: /\.tsx?$/, use: "ts-loader", exclude: /node_modules/, }, ], }, resolve: { extensions: [".tsx", ".ts", ".js"], }, }; export default config; 配置 { "scripts": { "build": "webpack --config webpack.config.ts" } } 測(cè)試對(duì) typescript 支持創(chuàng)建文件 const test = <T>(value: T) => { return value; }; const d = test(12); console.log(d); 在端執(zhí)行 支持 vuenpm i vue npm i vue-loader -D npm i vue-template-compiler -D
{ "exclude": ["node_modules", "dist"], "include": ["./src/**/*.ts", "./src/**/*.vue", "./src/**/*.js"] }
const VueLoaderPlugin = require("vue-loader/lib/plugin"); { module: { rules: [ { test: /\.vue$/, loader: "vue-loader", }, { test: /\.tsx?$/, loader: "ts-loader", options: { appendTsSuffixTo: [/\.vue$/], }, exclude: /node_modules/, }, ], }, plugins: [new VueLoaderPlugin()], } 類(lèi)寫(xiě)法需要安裝 npm i vue-class-component -D npm i vue-property-decorator -D
聲明文件 declare module "*.vue" { import Vue from "vue"; export default Vue; } 支持 sassnpm i sass-loader node-sass -D npm i style-loader css-loader sass-loader -D
module: { rules: [ ... // 普通的 `.scss` 文件和 `*.vue` 文件中的 // `<style lang="scss">` 塊都應(yīng)用它 { test: /\.scss$/, use: ["style-loader","css-loader", "sass-loader"], }, ], |
|
來(lái)自: 怡紅公子0526 > 《待分類(lèi)》