I am building a app with yew + tauri. I want to add node_modules to bundle with trunk. I basically need to do this https://tauri.app/v1/guides/features/window-customization/#js and call this api from my rust yew frontend.
Related
Could I treeshake node_modules when i build a nodejs backend project?
The node_modules is so big and there are too many small files in it,How can i treeshake it like the frontend do?
Too many small files in node_modules is not used in my project but when i want to deploy offline I must carry them from here to there.
node_modules
-- ramdajs
-- lodashjs
-- ...
How can I do treeshaking with node_modules in an express project.
I have created a Node.js app using typescript and trying to compile it. Currently, the build only contains the source files in the src folder. But I also want to include the dependencies like express, body-parser, etc from node_modules in the final build. This is similar to how webpack compiles all the files together creating bundles.
How can I do this using the typescript compiler only? Or it can be done using webpack only?
Please help.
Typescript compiler only compiles typescript to javascript. You have to manage yourself the build as you want.
I would use a post script to organize your program. Here is a example of pre and post script using npm run build Pre and post script gist
I have a project which is created in Electron.js. It uses simple HTML files. But now I want to convert this app into a React app.
While using HTML files directly, I am able to use node modules like electron, requiring main app.js file and all.
After building the project with webpack, the React app will get converted into static files. So how can I access the node modules after the build?
I suggest you to use Electron-React boilerplate for your project. As this contains all the basic configurations for building electron-react project. Go through the electron-react docs and setup an initial electron-react app.
# First, clone the repo via git:
git clone --depth=1 https://github.com/electron-react-boilerplate/electron-react-boilerplate.git your-project-name
cd your-project-name
# And then install dependencies with yarn:
yarn
All the modules listed on dependencies on package.json will be bundled in the production stage. So the relevant modules can be accessed on the build stage too. You can create components with your html files.
Make sure enable nodeIntegration on your BrowserWindow, so the nodemodules can be accessed by the renderer process.
webPreferences: {
nodeIntegration: true
}
you can use the electron-jsx package to work (I'm the author of the package), is simple and easy
Only you need that in you index.html file:
<script>
require("electron-jsx")(__dirname, {
reactDir: "./react-sources",
})
</script>
<script react-src="./react-sources/index.jsx">
And you can work with react normal (without webpack), and, additional, you can call any node package with ES6 import for react
More info and docs for the package:
https://www.npmjs.com/package/electron-jsx
https://github.com/mdjfs/electron-jsx
PD: You also need set nodeIntegration to true
My higher goal is to create a .zip file with the server bundle and all needed assets.
That file can be then moved to another device and executed there (the other device has the same NodeJS version installed). Building this on the device is not an option, because it's offline.
build/
|- node_modules //this is where I would like to have my externals
|- server.bundle.js
|- public/
My current solution is to pick and copy the external modules by hand, which is neither scalable nor convenient.
Would there be a possiblity, to let webpack handle this for me? Or even bundling externals like express into the bundle itself.
You could have just express in the dependencyarray on package.json, then run npm install --productionto just install that, so your node_modules is going to be small.
In the webpack config, you have to be sure to add externals (webpack_externals). Due to some binaries in some node dependencies, webpack is not able to bundle them together. You are going to have a require call for just those dependencies.
I have the Meteor app setup with such folder structure. I am not able to get the sass or scss file to create the appropriate css on its own and serve it to the client.
What should I do to make sass work as I prefer sass over scss.
Meteor supports less and stylus out of box my issuing meteor add less or meteor add stylus in your project root directory.
there is also a third party package repository (to be rolled into meteor core in the near future) on which you can find alternatives to many requirements.
For example, there is a third party scss package you can add to your project with meteorite add scss.
Now, the meteorite command here belongs to an npm package that interfaces your app to the atmosphere package repository as well as provide some deeper packaging structure to your app.
When you add the scss package, like in a typical meteor application your coffeescript, handlebars,jade,less,scss,javascript etc files will be compiled/bundled at deploy time and at each save afterwards and be placed in a hidden directory. So you will not be seeing your compiled css alongside your scss files, but the css will have been sent to the browser.