├── .gitignore
├── .idea
├── misc.xml
├── modules.xml
├── nuxt-library-demo.iml
└── vcs.xml
├── README.md
├── gulpHelper.js
├── lerna.json
├── package.json
├── packages
├── nuxt-app
│ ├── .gitignore
│ ├── README.md
│ ├── assets
│ │ └── README.md
│ ├── components
│ │ ├── Logo.vue
│ │ └── README.md
│ ├── layouts
│ │ ├── README.md
│ │ └── default.vue
│ ├── middleware
│ │ └── README.md
│ ├── nuxt.config.js
│ ├── package-lock.json
│ ├── package.json
│ ├── pages
│ │ ├── README.md
│ │ └── index.vue
│ ├── plugins
│ │ ├── README.md
│ │ └── my-component-library.js
│ ├── static
│ │ ├── README.md
│ │ └── favicon.ico
│ └── store
│ │ └── README.md
└── test-component-lib
│ ├── .gitignore
│ ├── README.md
│ ├── assets
│ └── images
│ │ └── unknown_user.png
│ ├── demo
│ ├── Demo.vue
│ ├── index.html
│ └── main.js
│ ├── gulpfile.js
│ ├── package-lock.json
│ ├── package.json
│ ├── shim.d.ts
│ ├── src
│ ├── components
│ │ ├── Test.vue
│ │ └── index.ts
│ ├── config
│ │ └── tailwind.js
│ ├── index.ts
│ ├── loader.js
│ ├── module.ts
│ └── styles
│ │ ├── _tailwind.scss
│ │ └── my-custom-library-base.scss
│ ├── tsconfig.json
│ ├── types
│ └── globals.d.ts
│ ├── webpack.base.js
│ ├── webpack.config.js
│ ├── webpack.demo.config.js
│ ├── webpack.lib.client.config.js
│ ├── webpack.lib.modern.config.js
│ ├── webpack.lib.server.config.js
│ └── webpack.module.config.js
└── tsconfig.json
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Node template
3 | # Logs
4 | logs
5 | *.log
6 | npm-debug.log*
7 | yarn-debug.log*
8 | yarn-error.log*
9 |
10 | # Runtime data
11 | pids
12 | *.pid
13 | *.seed
14 | *.pid.lock
15 |
16 | # Directory for instrumented libs generated by jscoverage/JSCover
17 | lib-cov
18 |
19 | # Coverage directory used by tools like istanbul
20 | coverage
21 |
22 | # nyc test coverage
23 | .nyc_output
24 |
25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26 | .grunt
27 |
28 | # Bower dependency directory (https://bower.io/)
29 | bower_components
30 |
31 | # node-waf configuration
32 | .lock-wscript
33 |
34 | # Compiled binary addons (https://nodejs.org/api/addons.html)
35 | build/Release
36 |
37 | # Dependency directories
38 | node_modules/
39 | jspm_packages/
40 |
41 | # TypeScript v1 declaration files
42 | typings/
43 |
44 | # Optional npm cache directory
45 | .npm
46 |
47 | # Optional eslint cache
48 | .eslintcache
49 |
50 | # Optional REPL history
51 | .node_repl_history
52 |
53 | # Output of 'npm pack'
54 | *.tgz
55 |
56 | # Yarn Integrity file
57 | .yarn-integrity
58 |
59 | # dotenv environment variables file
60 | .env
61 |
62 | # parcel-bundler cache (https://parceljs.org/)
63 | .cache
64 |
65 | # next.js build output
66 | .next
67 |
68 | # nuxt.js build output
69 | .nuxt
70 |
71 | # Nuxt generate
72 | dist
73 |
74 | # vuepress build output
75 | .vuepress/dist
76 |
77 | # Serverless directories
78 | .serverless
79 |
80 | # IDE / Editor
81 | .idea
82 | .editorconfig
83 |
84 | # Service worker
85 | sw.*
86 |
87 | # Mac OSX
88 | .DS_Store
89 |
90 | .tmp
91 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/nuxt-library-demo.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # nuxt library demo
2 |
3 | this repo is demonstrates how you can build your own library to use for nuxt. (it's a monorepo with a nuxt app and nuxt library in it)
4 |
5 | I'm using:
6 | * webpack to build a library that can be rendered on server and on client
7 | * tailwind to demonstrate how you can extend your library
8 | * custom assets to export via module
9 | * optimized server side rendering even for stylesheets
10 |
11 | See also https://cmty.app/nuxt/nuxt.js/issues/c9554
12 |
13 |
14 | ## get started
15 | to install needed dependencies
16 | * npm install && npm run bootstrap
17 |
18 | ### build library
19 | npm run build-lib
20 |
21 | ### start nuxt dev server
22 | npm run dev
23 |
24 | # some notes
25 | ### package.json sideEffects
26 | if you set sideEffecs to false, css gets removed. Therefore I added "sideEffects": [
27 | "*.css",
28 | "*.scss",
29 | "*.vue"
30 | ]
31 |
32 | ### gulp
33 | I'm using gulp to build 3 + 1 module in parallel. I build a modern version, a client version (es5) and a ssr/server version. Futhermore a nuxt module
34 | is built to register assets that your library is using.
35 |
36 | ### the nuxt module
37 | the module is actually a "trick" to automatically register all assets this library exposes. If you do not use nuxt and would like to use a library that has
38 | more assets and they are not packed within webpack than you woudl have to deal with it by yourself. The module approach solve this for you in background.
39 |
40 | I added two subfoldesr in assets "images" (for png,jpg,svg,etc) and fonts (woff2,svg,..etc) to demonstrate this. the fonts directory is empty though, play around with it ;)
41 |
42 | ### demo
43 | there is a demo file included, you can run the library with it by itself. type "npm run dev-lib" to start it.
44 |
45 | ### async components
46 | all components are async exported, check out the componets/index.ts file.
47 | This is the syntax for async components export: "() => import(...);" which allows webpack to split up the bundle in more smaller chunks.
48 |
49 | ### webpack and monorepo.
50 | very important when using a monorepo like this one here, ensure that webpack resolve.symlinks is false.
51 |
52 | ### vue and monoprepo.
53 | beware that a monorepo can install vue in a a lot of different locations (there are more than one node_modules directories). therefore it is
54 | super important to hoist your dependencies (which means all node_modules are installed in the root).
55 | e.g. if you see something like Property or method "_ssrNode" is not defined on the instance but referenced during render. , you probably
56 | have multiple instances of vue lying around.
57 |
58 | ### using you component library within nuxt (step by step):
59 | * add your component as module (nuxt.config.js)
60 | ```js
61 | modules: [
62 | // load components library as module
63 | path.join(path.dirname(require.resolve('test-component-lib')), '/module')
64 | ]
65 | ```
66 | * add your componetn as plugin (i know the module could registe a plugin too, I welcome any PR on this ;))
67 | ```js
68 | plugins: [
69 | // load components library as plugin
70 | '~/plugins/my-component-library'
71 | ],
72 | ```
73 | * create the plugin, e.g.:
74 | ~/plugins/my-component-library
75 | ```js
76 | import Vue from 'vue';
77 | import SharedComponentsPlugin from 'test-component-lib';
78 |
79 | export default ctx => {
80 | const { app } = ctx;
81 | Vue.use(SharedComponentsPlugin, {
82 | publicPath: process.env.publicPath,
83 | moment: ctx.$moment
84 | });
85 | };
86 | ```
87 |
88 | * use the component like you would do normally:
89 | ```vue
90 |
91 | hallo2
92 |
93 |
94 |
103 | ```
104 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/gulpHelper.js:
--------------------------------------------------------------------------------
1 | const WebpackBar = require('webpackbar');
2 | const webpack = require('webpack');
3 | const gutil = require("gulp-util");
4 |
5 | const runWebpack = async (name, webpackConfig) => {
6 | let color;
7 | switch (name) {
8 | case 'server':
9 | color = 'blue';
10 | break;
11 | case 'modern':
12 | color = 'yellow';
13 | break;
14 | default:
15 | color = 'green';
16 | }
17 |
18 | return new Promise((resolve, reject) => {
19 | webpack(
20 | {
21 | ...webpackConfig,
22 | plugins: [
23 | ...webpackConfig.plugins,
24 | new WebpackBar({ name, color })
25 | ]
26 | },
27 | (err, stats) => {
28 | if(err) {
29 | reject(new gutil.PluginError("webpack", err));
30 | return;
31 | }
32 | gutil.log("[webpack]", stats.toString({
33 | colors: true
34 | }));
35 |
36 | if (stats.hasErrors()) {
37 | reject(new Error('build failed'));
38 | } else {
39 | resolve();
40 | }
41 | }
42 | );
43 | });
44 | };
45 |
46 | exports.runWebpack = runWebpack;
47 |
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "packages": [
3 | "packages/*"
4 | ],
5 | "version": "0.0.0"
6 | }
7 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "root",
3 | "private": true,
4 | "devDependencies": {
5 | "lerna": "^3.16.4",
6 | "gulp": "^4.0.2",
7 | "gulp-util": "^3.0.8"
8 | },
9 | "scripts": {
10 | "bootstrap": "lerna bootstrap --hoist",
11 | "dev-lib": "cd packages/test-component-lib && npm run dev",
12 | "build-lib": "cd packages/test-component-lib && npm run build",
13 | "dev": "cd packages/nuxt-app && npm run dev"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/packages/nuxt-app/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Node template
3 | # Logs
4 | logs
5 | *.log
6 | npm-debug.log*
7 | yarn-debug.log*
8 | yarn-error.log*
9 |
10 | # Runtime data
11 | pids
12 | *.pid
13 | *.seed
14 | *.pid.lock
15 |
16 | # Directory for instrumented libs generated by jscoverage/JSCover
17 | lib-cov
18 |
19 | # Coverage directory used by tools like istanbul
20 | coverage
21 |
22 | # nyc test coverage
23 | .nyc_output
24 |
25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26 | .grunt
27 |
28 | # Bower dependency directory (https://bower.io/)
29 | bower_components
30 |
31 | # node-waf configuration
32 | .lock-wscript
33 |
34 | # Compiled binary addons (https://nodejs.org/api/addons.html)
35 | build/Release
36 |
37 | # Dependency directories
38 | node_modules/
39 | jspm_packages/
40 |
41 | # TypeScript v1 declaration files
42 | typings/
43 |
44 | # Optional npm cache directory
45 | .npm
46 |
47 | # Optional eslint cache
48 | .eslintcache
49 |
50 | # Optional REPL history
51 | .node_repl_history
52 |
53 | # Output of 'npm pack'
54 | *.tgz
55 |
56 | # Yarn Integrity file
57 | .yarn-integrity
58 |
59 | # dotenv environment variables file
60 | .env
61 |
62 | # parcel-bundler cache (https://parceljs.org/)
63 | .cache
64 |
65 | # next.js build output
66 | .next
67 |
68 | # nuxt.js build output
69 | .nuxt
70 |
71 | # Nuxt generate
72 | dist
73 |
74 | # vuepress build output
75 | .vuepress/dist
76 |
77 | # Serverless directories
78 | .serverless
79 |
80 | # IDE / Editor
81 | .idea
82 | .editorconfig
83 |
84 | # Service worker
85 | sw.*
86 |
87 | # Mac OSX
88 | .DS_Store
--------------------------------------------------------------------------------
/packages/nuxt-app/README.md:
--------------------------------------------------------------------------------
1 | # test-nuxt-app
2 |
3 | > My finest Nuxt.js project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | $ npm run install
10 |
11 | # serve with hot reload at localhost:3000
12 | $ npm run dev
13 |
14 | # build for production and launch server
15 | $ npm run build
16 | $ npm run start
17 |
18 | # generate static project
19 | $ npm run generate
20 | ```
21 |
22 | For detailed explanation on how things work, checkout [Nuxt.js docs](https://nuxtjs.org).
23 |
--------------------------------------------------------------------------------
/packages/nuxt-app/assets/README.md:
--------------------------------------------------------------------------------
1 | # ASSETS
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | This directory contains your un-compiled assets such as LESS, SASS, or JavaScript.
6 |
7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked).
8 |
--------------------------------------------------------------------------------
/packages/nuxt-app/components/Logo.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
80 |
--------------------------------------------------------------------------------
/packages/nuxt-app/components/README.md:
--------------------------------------------------------------------------------
1 | # COMPONENTS
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | The components directory contains your Vue.js Components.
6 |
7 | _Nuxt.js doesn't supercharge these components._
8 |
--------------------------------------------------------------------------------
/packages/nuxt-app/layouts/README.md:
--------------------------------------------------------------------------------
1 | # LAYOUTS
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | This directory contains your Application Layouts.
6 |
7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/views#layouts).
8 |
--------------------------------------------------------------------------------
/packages/nuxt-app/layouts/default.vue:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
19 |
20 |
52 |
--------------------------------------------------------------------------------
/packages/nuxt-app/plugins/README.md:
--------------------------------------------------------------------------------
1 | # PLUGINS
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | This directory contains Javascript plugins that you want to run before mounting the root Vue.js application.
6 |
7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/plugins).
8 |
--------------------------------------------------------------------------------
/packages/nuxt-app/plugins/my-component-library.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import SharedComponentsPlugin from 'test-component-lib';
3 |
4 | export default ctx => {
5 | const { app } = ctx;
6 | Vue.use(SharedComponentsPlugin, {
7 | publicPath: process.env.publicPath,
8 | moment: ctx.$moment
9 | });
10 | };
11 |
--------------------------------------------------------------------------------
/packages/nuxt-app/static/README.md:
--------------------------------------------------------------------------------
1 | # STATIC
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | This directory contains your static files.
6 | Each file inside this directory is mapped to `/`.
7 | Thus you'd want to delete this README.md before deploying to production.
8 |
9 | Example: `/static/robots.txt` is mapped as `/robots.txt`.
10 |
11 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#static).
12 |
--------------------------------------------------------------------------------
/packages/nuxt-app/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simllll/nuxt-library-demo/c3cdceb03956615d0667a913999cc4734ace74c1/packages/nuxt-app/static/favicon.ico
--------------------------------------------------------------------------------
/packages/nuxt-app/store/README.md:
--------------------------------------------------------------------------------
1 | # STORE
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | This directory contains your Vuex Store files.
6 | Vuex Store option is implemented in the Nuxt.js framework.
7 |
8 | Creating a file in this directory automatically activates the option in the framework.
9 |
10 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/vuex-store).
11 |
--------------------------------------------------------------------------------
/packages/test-component-lib/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simllll/nuxt-library-demo/c3cdceb03956615d0667a913999cc4734ace74c1/packages/test-component-lib/.gitignore
--------------------------------------------------------------------------------
/packages/test-component-lib/README.md:
--------------------------------------------------------------------------------
1 | this is a component library that you can use withing a nuxt project.
2 |
3 | it was a lot of work to get this thing running, so maybe you can reference somewhere to hokify.at/hokify.de or just hokify.com
4 | if you can make use of this library demo.
5 |
6 | thanks
7 |
8 | (c) by simon tretter (simon.tretter@hokify.com)
9 |
--------------------------------------------------------------------------------
/packages/test-component-lib/assets/images/unknown_user.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simllll/nuxt-library-demo/c3cdceb03956615d0667a913999cc4734ace74c1/packages/test-component-lib/assets/images/unknown_user.png
--------------------------------------------------------------------------------
/packages/test-component-lib/demo/Demo.vue:
--------------------------------------------------------------------------------
1 |
2 |