The cause of
Recently found a fun CSS tool library: tailwindcss, can control various styles through the particle class name, let me write CSS code, configure the custom theme plus vscode plug-in hint that those are really nice, easy.
after
I did a local build and found nothing wrong. Then I went to the test server and found that the Node version of the test server was 11.0.0. Then I looked for the documentation and found that the tailwindcss required 12.13 or more. You want to upgrade the Node version, but this may cause problems: there are many projects on the server, and upgrading the version may cause problems for other projects.
At this point I came up with the idea of using the NPX command to dynamically package the Node version, keeping the NPM run build command to ensure the consistency of the build commands.
The results of
The package.json build command file has been modified as follows:
"scripts": {
"build": "node build",},Copy the code
/build/index.js: /build/index.js: /build/index.js: /build/index.js: /build/index.js
NPM install runjs --save-dev
const { run } = require('runjs');
// Use version 12.16.1 for customization
const needVersion = '12.16.1';
// Customize the build command
if (process.version === 'v' + needVersion) {
console.log(`begin build node version=${process.version}`);
// Build with vue-cli
run('vue-cli-service build');
} else {
// If the version is incorrect, install 12.16.1 and run build
Node 12.16.1 will be removed after build, which does not affect the global version
run(`npx node@${needVersion} build`);
}
Copy the code
This can only be used as a temporary solution, the project will take longer to build, and it is best to upgrade Node once and for all without risk.