Created
July 22, 2022 05:27
-
-
Save yagudaev/d94bb8f40c0665306d0947157b481e3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import HtmlWebpackInlineSourcePlugin from "@effortlessmotion/html-webpack-inline-source-plugin" | |
import HtmlWebpackPlugin from "html-webpack-plugin" | |
import path from "path" | |
import { fileURLToPath } from "url" | |
const __filename = fileURLToPath(import.meta.url) | |
const __dirname = path.dirname(__filename) | |
export default (env, argv) => ({ | |
mode: argv.mode === "production" ? "production" : "development", | |
// This is necessary because Figma's 'eval' works differently than normal eval | |
devtool: argv.mode === "production" ? false : "inline-source-map", | |
entry: { | |
ui: "./ui-src/main.tsx", // The entry point for your UI code | |
main: "./plugin-src/code.ts" // The entry point for your plugin code | |
}, | |
module: { | |
rules: [ | |
// Converts TypeScript code to JavaScript | |
{ | |
test: /ui-src\/.*\.tsx?$/, | |
loader: "ts-loader", | |
exclude: /node_modules/, | |
options: { configFile: "tsconfig.json" } | |
}, | |
{ | |
test: /plugin-src\/.*\.tsx?$/, | |
loader: "ts-loader", | |
exclude: /node_modules/, | |
options: { | |
configFile: "/Users/mike/code/conceptual/conceptual-figma-plugin/plugin-src/tsconfig.json" | |
} | |
}, | |
{ | |
test: /shared\/.*\.tsx?$/, | |
loader: "ts-loader", | |
exclude: /node_modules/, | |
options: { configFile: "tsconfig.json" } | |
}, | |
// Enables including CSS by doing "import './file.css'" in your TypeScript code | |
{ test: /\.css$/, use: ["style-loader", { loader: "css-loader" }] }, | |
// Allows you to use "<%= require('./file.svg') %>" in your HTML code to get a data URI | |
{ test: /\.(png|jpg|gif|webp|svg)$/, loader: "url-loader" } | |
] | |
}, | |
// Webpack tries these extensions for you if you omit the extension like "import './file'" | |
resolve: { extensions: [".tsx", ".ts", ".jsx", ".js"] }, | |
output: { | |
filename: "[name].js", | |
path: path.resolve(__dirname, "dist") // Compile into a folder called "dist" | |
}, | |
// Tells Webpack to generate "ui.html" and to inline "ui.ts" into it | |
plugins: [ | |
new HtmlWebpackPlugin({ | |
template: "./ui-src/index.html", | |
filename: "ui.html", | |
inlineSource: ".(js)$", | |
chunks: ["ui"] | |
}), | |
new HtmlWebpackInlineSourcePlugin() | |
] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment