Why does multiple project code need to be reused?
There will always be some related projects, their code is similar, package dependence is similar, many components, auxiliary code are the same, there is a great association between the project itself, for example, one is the back-end management front-end project, the other is the front-end system of the main project, when submitting deployment can be submitted together. To make this part of the common code more reusable, let’s talk about how I have multiple projects share package.json, and combine the common code in one place. So let’s get started…
Build a NUXT SSR project using official methods
npx create-nuxt-app example
Copy the code
Using the above command, the resulting project structure is shown below.
Modify the project structure to move the project to a subdirectory
Save the public configuration file in the original directory, package the project file and its configuration file, name it, and place it in the SRC directory.
Modify the configuration file nuxt.config.js
const domain = 'example.com'
export default {
srcDir: __dirname,
buildDir: `.nuxt/${domain}`}Copy the code
SrcDir Project folder path buildDir Project folder path after compilation so that the project path is reconfigured correctly and the generated files appear under.nuxt/example.com without conflict with other project files
Modify scripts in package.json
"scripts": {
"example:dev": "nuxt --config-file src/example.com/nuxt.config.js"."example:build": "NODE_ENV=production nuxt build --config-file src/example.com/nuxt.config.js"."example:start": "NODE_ENV=production nuxt start --config-file src/example.com/nuxt.config.js",}Copy the code
NPM run example:dev to run the modified directory project.
Interuse code between projects, common code collation
Steamstats. Cn Steam game online statistics, leave a link outside