├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── README.md ├── example ├── .babelrc ├── .browserslistrc ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .lintstagedrc.json ├── .prettierrc.js ├── .vscode │ └── setting.json ├── README.md ├── package-lock.json ├── package.json ├── postcss.config.js ├── project.config.json ├── src │ ├── app.mina │ ├── common.wxss │ ├── components │ │ ├── bar.mina │ │ ├── circular.mina │ │ ├── classical.js │ │ ├── classical.json │ │ ├── classical.wxml │ │ └── foobar.mina │ ├── images │ │ ├── logo.png │ │ └── tabs │ │ │ ├── bell-active.png │ │ │ ├── bell.png │ │ │ ├── home-active.png │ │ │ └── home.png │ ├── packages │ │ └── a │ │ │ └── pages │ │ │ └── home.mina │ ├── pages │ │ ├── home.mina │ │ └── message.mina │ ├── template │ │ └── greeting.wxml │ ├── utils │ │ └── dependency.js │ └── wxs │ │ ├── datetime │ │ └── now.wxs │ │ ├── greeting.wxs │ │ └── string │ │ └── padding.wxs └── webpack.config.js ├── lerna.json ├── package-lock.json ├── package.json └── packages ├── mina-entry-webpack-plugin ├── .gitignore ├── .lintstagedrc.json ├── .prettierrc.js ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src │ ├── config-readers │ │ ├── classical.ts │ │ └── mina.ts │ ├── helpers │ │ ├── entry.ts │ │ └── index.ts │ ├── index.ts │ ├── interfaces │ │ └── config-reader.ts │ └── loaders │ │ └── virtual-mina-loader.ts ├── test │ └── helpers │ │ └── entry.test.ts └── tsconfig.json ├── mina-loader ├── .gitignore ├── .lintstagedrc.json ├── .prettierrc.js ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src │ ├── constants.ts │ ├── deps.d.ts │ ├── helpers.ts │ ├── index.ts │ └── loaders │ │ ├── mina-json.ts │ │ ├── mina.ts │ │ ├── parser.ts │ │ ├── selector.ts │ │ └── wxss-url.ts ├── test │ ├── basic.js │ ├── enforce-relative-path.js │ ├── extensions.js │ ├── fixtures │ │ ├── basic │ │ │ ├── app.mina │ │ │ ├── cloud-url.mina │ │ │ ├── dependency.a.js │ │ │ ├── dependency.b.js │ │ │ ├── empty.mina │ │ │ ├── logo.png │ │ │ ├── logo.png.txt │ │ │ └── page.mina │ │ ├── enforce-relative-path │ │ │ └── page.mina │ │ ├── entry │ │ │ ├── app-basic.mina │ │ │ ├── app-custom-extensions.mina │ │ │ ├── app-inline-loaders.mina │ │ │ ├── app-non-extname.mina │ │ │ ├── app-not-existed-file.mina │ │ │ ├── app-symbolic.mina │ │ │ ├── app-unknown-file-type.mina │ │ │ ├── app-virtual-extname.mina │ │ │ ├── component-a.mina │ │ │ ├── component-b.json │ │ │ ├── component-c.mina │ │ │ ├── hi.js │ │ │ ├── logo.png │ │ │ ├── page-a.mina │ │ │ ├── page-b.mina │ │ │ ├── page-c.js │ │ │ ├── page-c.json │ │ │ ├── page-d.wxml │ │ │ ├── page-e.json │ │ │ ├── page-f.wxss │ │ │ ├── page-g.yaml │ │ │ ├── page-h.ttml │ │ │ ├── page-i.js │ │ │ ├── page-i.ttml │ │ │ ├── symbolic-a.mina │ │ │ └── symbolic-b.mina │ │ ├── extra-resources │ │ │ ├── github.mina │ │ │ ├── github.png │ │ │ ├── subdir │ │ │ │ └── symbolic-b.mina │ │ │ └── symbolic-a.mina │ │ ├── json5 │ │ │ └── component.mina │ │ ├── lang │ │ │ ├── basic.mina │ │ │ ├── custom-rule.mina │ │ │ └── override-loader.mina │ │ ├── resolve-components │ │ │ ├── node_modules │ │ │ │ ├── logo.mina │ │ │ │ │ ├── dist │ │ │ │ │ │ └── logo.mina │ │ │ │ │ └── package.json │ │ │ │ └── tab │ │ │ │ │ ├── package.json │ │ │ │ │ ├── tab-item.mina │ │ │ │ │ └── tab.mina │ │ │ └── src │ │ │ │ ├── app.mina │ │ │ │ ├── components │ │ │ │ ├── a.mina │ │ │ │ └── b.mina │ │ │ │ └── pages │ │ │ │ ├── c.mina │ │ │ │ ├── d.mina │ │ │ │ └── home.mina │ │ ├── separation │ │ │ ├── anotherUtil.ts │ │ │ ├── es-page.es │ │ │ ├── es-page.mina │ │ │ ├── simple-page.mina │ │ │ ├── simple-page.wxml │ │ │ ├── simple-page.wxss │ │ │ ├── ts-page.mina │ │ │ ├── ts-page.ts │ │ │ └── tsconfig.json │ │ ├── subpackages │ │ │ └── src │ │ │ │ ├── app.mina │ │ │ │ ├── components │ │ │ │ ├── a.mina │ │ │ │ ├── b.mina │ │ │ │ ├── c.mina │ │ │ │ └── d.mina │ │ │ │ ├── pages │ │ │ │ └── home.mina │ │ │ │ ├── sub1 │ │ │ │ ├── page1.mina │ │ │ │ └── page2.mina │ │ │ │ └── sub2 │ │ │ │ └── page1.mina │ │ ├── template │ │ │ ├── header.wxml │ │ │ ├── import.mina │ │ │ ├── include.mina │ │ │ ├── inline.mina │ │ │ ├── logo.png │ │ │ ├── message.wxml │ │ │ └── subdir │ │ │ │ └── page.mina │ │ └── wxss │ │ │ ├── cdn │ │ │ └── postcss.config.js │ │ │ ├── page.mina │ │ │ └── url │ │ │ └── postcss.config.js │ ├── helpers │ │ ├── babelrc │ │ ├── compiler.js │ │ ├── config-readers │ │ │ └── yaml-to-mina-config-reader.js │ │ ├── loaders │ │ │ ├── debug-loader.js │ │ │ ├── nothing-loader.js │ │ │ ├── replace-blue-to-yellow.js │ │ │ ├── scope-id-loader.js │ │ │ └── yaml-to-mina-loader.js │ │ └── transform │ │ │ └── scope-id.js │ ├── json5.js │ ├── lang.js │ ├── mina-entry-plugin.js │ ├── mina-runtime-plugin.js │ ├── resolve-components.js │ ├── separation.js │ ├── subpackages.js │ ├── template.js │ ├── transform.js │ └── wxss.js └── tsconfig.json ├── mina-runtime-webpack-plugin ├── .gitignore ├── .lintstagedrc.json ├── .prettierrc.js ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── polyfill.js ├── src │ └── index.ts └── tsconfig.json └── wxs-loader ├── .gitignore ├── .lintstagedrc.json ├── .prettierrc.js ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src ├── helpers │ ├── extract.js │ ├── get-public-path.js │ ├── load-module.js │ ├── relative.js │ ├── resolve.js │ ├── to-safe-output-path.js │ └── visit.js └── index.js ├── test ├── fixtures │ ├── constants.wxs │ ├── greet.wxs │ ├── padding.wxs │ └── pokemon │ │ └── eevee.wxs ├── helpers │ └── compiler.js ├── snapshots │ ├── wxs.js.md │ └── wxs.js.snap └── wxs.js └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.mina linguist-language=Vue 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # dev 2 | .DS_Store 3 | node_modules 4 | !/packages/mina-loader/test/fixtures/resolve-components/node_modules 5 | npm-debug.log 6 | lerna-debug.log 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "12" 5 | - "10" 6 | 7 | cache: 8 | directories: 9 | - $HOME/.npm 10 | 11 | before_install: 12 | - npm install --global npm@latest 13 | - npm --version 14 | 15 | install: 16 | - npx lerna bootstrap --ci 17 | 18 | script: 19 | - npx lerna run test 20 | 21 | notifications: 22 | webhooks: "https://www.travisbuddy.com/" 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

mina-webpack

2 |

Mina single-file-component meets Webpack

3 |

4 | 5 | [![Build Status](https://travis-ci.org/tinajs/mina-webpack.svg?branch=master)](https://travis-ci.org/tinajs/mina-webpack) 6 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 7 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Ftinajs%2Fmina-webpack.svg?type=small)](https://app.fossa.io/projects/git%2Bgithub.com%2Ftinajs%2Fmina-webpack?ref=badge_small) 8 | 9 | ## Get Started 10 | 11 | We recommend you to get started with [template-mina](https://github.com/tinajs/template-mina): 12 | 13 | ```bash 14 | npm i -g sao 15 | 16 | sao mina my-app 17 | cd my-app 18 | npm start 19 | ``` 20 | 21 | And see how to use with [TinaJS](https://tinajs.github.io/tina/#/guide/package-management-and-build-tools) 22 | 23 | ## Packages included 24 | 25 | - [mina-loader](./packages/mina-loader) 26 | 27 | [![npm](https://img.shields.io/npm/v/@tinajs/mina-loader.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/mina-loader) 28 | [![npm](https://img.shields.io/npm/dw/@tinajs/mina-loader.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/mina-loader) 29 | [![license](https://img.shields.io/npm/l/@tinajs/mina-loader.svg?style=flat-square)](./LICENSE) 30 | 31 | - [mina-runtime-webpack-plugin](./packages/mina-runtime-webpack-plugin) 32 | 33 | [![npm](https://img.shields.io/npm/v/@tinajs/mina-runtime-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/mina-runtime-webpack-plugin) 34 | [![npm](https://img.shields.io/npm/dw/@tinajs/mina-runtime-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/mina-runtime-webpack-plugin) 35 | [![license](https://img.shields.io/npm/l/@tinajs/mina-runtime-webpack-plugin.svg?style=flat-square)](./LICENSE) 36 | 37 | - [mina-entry-webpack-plugin](./packages/mina-entry-webpack-plugin) 38 | 39 | [![npm](https://img.shields.io/npm/v/@tinajs/mina-entry-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/mina-entry-webpack-plugin) 40 | [![npm](https://img.shields.io/npm/dw/@tinajs/mina-entry-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/mina-entry-webpack-plugin) 41 | [![license](https://img.shields.io/npm/l/@tinajs/mina-entry-webpack-plugin.svg?style=flat-square)](./LICENSE) 42 | 43 | - [wxs-loader](./packages/wxs-loader) 44 | 45 | [![npm](https://img.shields.io/npm/v/@tinajs/wxs-loader.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/wxs-loader) 46 | [![npm](https://img.shields.io/npm/dw/@tinajs/wxs-loader.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/wxs-loader) 47 | [![license](https://img.shields.io/npm/l/@tinajs/wxs-loader.svg?style=flat-square)](./LICENSE) 48 | 49 | ## Manual Installation 50 | 51 | ```bash 52 | npm i --save-dev \ 53 | @tinajs/mina-entry-webpack-plugin \ 54 | @tinajs/mina-runtime-webpack-plugin \ 55 | @tinajs/mina-loader \ 56 | @tinajs/wxs-loader 57 | ``` 58 | 59 | ## Simplest Usage 60 | 61 | **webpack.config.js**: 62 | 63 | ```javascript 64 | const webpack = require("webpack"); 65 | const MinaEntryPlugin = require("@tinajs/mina-entry-webpack-plugin"); 66 | const MinaRuntimePlugin = require("@tinajs/mina-runtime-webpack-plugin"); 67 | const resolve = require("path").resolve; 68 | 69 | module.exports = { 70 | context: resolve("src"), 71 | entry: "./app.mina", 72 | output: { 73 | path: resolve("dist"), 74 | filename: "[name]", 75 | publicPath: "/", 76 | globalObject: "wx" 77 | }, 78 | module: { 79 | rules: [ 80 | { 81 | test: /\.mina$/, 82 | use: { 83 | loader: "@tinajs/mina-loader", 84 | options: { 85 | loaders: { 86 | script: "babel-loader" 87 | } 88 | } 89 | } 90 | }, 91 | { 92 | test: /\.wxs$/, 93 | use: [ 94 | { 95 | loader: '@tinajs/wxs-loader', 96 | options: { 97 | name: 'wxs/[name].[hash:6].[ext]', 98 | }, 99 | }, 100 | ], 101 | }, 102 | ] 103 | }, 104 | plugins: [ 105 | new MinaEntryPlugin({ 106 | map: entry => ["es6-promise/dist/es6-promise.auto.js", entry] 107 | }), 108 | new MinaRuntimePlugin() 109 | ], 110 | optimization: { 111 | splitChunks: { 112 | chunks: 'all', 113 | name: "common.js", 114 | minChunks: 2, 115 | minSize: 0 116 | }, 117 | runtimeChunk: { 118 | name: "runtime.js" 119 | } 120 | }, 121 | mode: "none" 122 | }; 123 | ``` 124 | 125 | **app.mina**: 126 | 127 | ```xml 128 | 129 | { 130 | "pages": [ 131 | "page.mina" 132 | ] 133 | } 134 | 135 | 136 | 144 | ``` 145 | 146 | **page.mina**: 147 | 148 | ```xml 149 | 150 | { 151 | "window":{ 152 | "navigationBarTitleText": "Hello, World!" 153 | } 154 | } 155 | 156 | 157 | 162 | 163 | 168 | 169 | 179 | ``` 180 | 181 | ## Examples 182 | 183 | - [mina-webpack - Full Example](./example) 184 | - [mina-loader - test](./packages/mina-loader/test) 185 | - [wxs-loader - test](./packages/wxs-loader/test) 186 | - [TinaJS - HackerNews Reader](https://github.com/tinajs/tina-hackernews) 187 | 188 | ## Related Projects 189 | 190 | ### Best to use with 191 | 192 | - [TinaJS](https://github.com/tinajs/tina) 193 | 194 | ### Scaffolds 195 | 196 | - [template-mina](https://github.com/tinajs/template-mina) 197 | - [ambar/new-mina](https://github.com/ambar/new-mina) 198 | 199 | ### Other package compiler (also alternatives) 200 | 201 | - [gulp-mina](https://github.com/tinajs/gulp-mina) 202 | 203 | ### Got inspiration from 204 | 205 | - [Cap32/wxapp-webpack-plugin](https://github.com/Cap32/wxapp-webpack-plugin) 206 | - [CantonJS/wxapp-boilerplate](https://github.com/cantonjs/wxapp-boilerplate) 207 | - [zezhipeng/mina-loader](https://github.com/zezhipeng/mina-loader) 208 | - [Vue - Single File Component](https://vuejs.org/v2/guide/single-file-components.html) 209 | 210 | [![](https://github.com/tinajs/assets/raw/master/images/banners/sponsored.png)](https://github.com/tinajs/tina) 211 | -------------------------------------------------------------------------------- /example/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["@babel/preset-env", { 4 | "modules": false, 5 | "loose": true 6 | }] 7 | ], 8 | "plugins": [ 9 | ["@babel/plugin-transform-runtime", { 10 | "corejs": 2 11 | }], 12 | "@babel/plugin-proposal-class-properties", 13 | "@babel/plugin-proposal-export-default-from" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /example/.browserslistrc: -------------------------------------------------------------------------------- 1 | iOS 8 2 | ChromeAndroid 53 3 | -------------------------------------------------------------------------------- /example/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /example/.gitattributes: -------------------------------------------------------------------------------- 1 | # GitLab 2 | # https://docs.gitlab.com/ee/user/project/highlighting.html 3 | *.wxml gitlab-language=xml 4 | *.wxss gitlab-language=css 5 | *.wxs gitlab-language=js 6 | *.mina gitlab-language=html 7 | 8 | # GitHub 9 | # https://github.com/github/linguist#overrides 10 | *.wxml linguist-language=xml 11 | *.wxss linguist-language=css 12 | *.wxs linguist-language=js 13 | *.mina linguist-language=html 14 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | /dist 2 | -------------------------------------------------------------------------------- /example/.lintstagedrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "linters": { 3 | "*.{md,js,json}": ["prettier --write", "git add"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /example/.prettierrc.js: -------------------------------------------------------------------------------- 1 | // @see https://prettier.io/docs/en/options.html 2 | module.exports = { 3 | semi: false, 4 | singleQuote: true, 5 | trailingComma: 'es5', 6 | } 7 | -------------------------------------------------------------------------------- /example/.vscode/setting.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.wxml": "xml", 4 | "*.wxss": "css", 5 | "*.wxs": "js", 6 | "*.mina": "vue" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # mina-webpack-examples 2 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tinajs/mina-webpack-examples", 3 | "private": true, 4 | "description": "", 5 | "main": "index.js", 6 | "author": "yelo", 7 | "license": "MIT", 8 | "scripts": { 9 | "clean": "rimraf \"./dist/!(app.json)**\"", 10 | "precommit": "lint-staged", 11 | "prestart": "run-s clean", 12 | "prebuild": "run-s clean", 13 | "start": "webpack --watch --progress", 14 | "build": "cross-env NODE_ENV=production webpack" 15 | }, 16 | "dependencies": { 17 | "@tinajs/tina-logo.mina": "^0.2.1", 18 | "@vant/weapp": "^1.3.2", 19 | "cowsay": "^1.5.0", 20 | "es6-promise": "^4.2.4", 21 | "iview-weapp": "^2.0.0" 22 | }, 23 | "devDependencies": { 24 | "@babel/core": "^7.1.0", 25 | "@babel/plugin-proposal-class-properties": "^7.1.0", 26 | "@babel/plugin-proposal-export-default-from": "^7.0.0", 27 | "@babel/plugin-transform-runtime": "^7.1.0", 28 | "@babel/preset-env": "^7.1.0", 29 | "@babel/runtime-corejs2": "^7.0.0", 30 | "@tinajs/mina-entry-webpack-plugin": "^1.5.0", 31 | "@tinajs/mina-loader": "^1.9.0", 32 | "@tinajs/mina-runtime-webpack-plugin": "^1.3.6", 33 | "@tinajs/wxml-loader": "0.3.1-fork.1", 34 | "@tinajs/wxs-loader": "^1.2.10", 35 | "babel-loader": "^8.0.4", 36 | "cross-env": "^5.1.1", 37 | "file-loader": "^1.1.11", 38 | "json5": "^2.2.2", 39 | "lint-staged": "^7.2.0", 40 | "npm-run-all": "^4.1.2", 41 | "postcss-loader": "^7.3.3", 42 | "precss": "^4.0.0", 43 | "prettier": "^1.19.1", 44 | "relative-file-loader": "^1.1.12", 45 | "rimraf": "^2.6.2", 46 | "uglifyjs-webpack-plugin": "^1.2.7", 47 | "url-loader": "^0.6.2", 48 | "webpack": "^5.94.0", 49 | "webpack-cli": "^3.3.12" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /example/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [require('precss')()], 3 | } 4 | -------------------------------------------------------------------------------- /example/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "miniprogramRoot": "./dist", 3 | "compileType": "miniprogram", 4 | "setting": { 5 | "es6": false, 6 | "postcss": false, 7 | "minified": false, 8 | "uglifyFileName": false, 9 | "newFeature": true 10 | }, 11 | "appid": "", 12 | "projectname": "mina-webpack-example" 13 | } 14 | -------------------------------------------------------------------------------- /example/src/app.mina: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "pages": [ 4 | "pages/home.mina", 5 | "pages/message.mina" 6 | ], 7 | "subPackages": [ 8 | { 9 | "root": "packages/a", 10 | "pages": [ 11 | "pages/home.mina" 12 | ] 13 | } 14 | ], 15 | "tabBar": { 16 | "list": [ 17 | { 18 | "pagePath": "pages/home.mina", 19 | "text": "Home", 20 | "iconPath": "./images/tabs/home.png", 21 | "selectedIconPath": "./images/tabs/home-active.png" 22 | }, 23 | { 24 | "pagePath": "pages/message.mina", 25 | "text": "Message", 26 | "iconPath": "./images/tabs/bell.png", 27 | "selectedIconPath": "./images/tabs/bell-active.png" 28 | } 29 | ] 30 | } 31 | } 32 | 33 | 34 | 43 | -------------------------------------------------------------------------------- /example/src/common.wxss: -------------------------------------------------------------------------------- 1 | page { 2 | font-size: 12px; 3 | } 4 | -------------------------------------------------------------------------------- /example/src/components/bar.mina: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "component": true 4 | } 5 | 6 | 7 | 10 | 11 | 15 | -------------------------------------------------------------------------------- /example/src/components/circular.mina: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "usingComponents": { 4 | "circular": "circular.mina" 5 | }, 6 | "component": true 7 | } 8 | 9 | 10 | 13 | 14 | 18 | -------------------------------------------------------------------------------- /example/src/components/classical.js: -------------------------------------------------------------------------------- 1 | Component({}) 2 | -------------------------------------------------------------------------------- /example/src/components/classical.json: -------------------------------------------------------------------------------- 1 | { 2 | "component": true 3 | } 4 | -------------------------------------------------------------------------------- /example/src/components/classical.wxml: -------------------------------------------------------------------------------- 1 | classical component 2 | -------------------------------------------------------------------------------- /example/src/components/foobar.mina: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "usingComponents": { 4 | "bar": "./bar.mina" 5 | }, 6 | "component": true 7 | } 8 | 9 | 10 | 13 | 14 | 18 | -------------------------------------------------------------------------------- /example/src/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinajs/mina-webpack/954761f689772903fd7b2d3f83d1493435818076/example/src/images/logo.png -------------------------------------------------------------------------------- /example/src/images/tabs/bell-active.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinajs/mina-webpack/954761f689772903fd7b2d3f83d1493435818076/example/src/images/tabs/bell-active.png -------------------------------------------------------------------------------- /example/src/images/tabs/bell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinajs/mina-webpack/954761f689772903fd7b2d3f83d1493435818076/example/src/images/tabs/bell.png -------------------------------------------------------------------------------- /example/src/images/tabs/home-active.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinajs/mina-webpack/954761f689772903fd7b2d3f83d1493435818076/example/src/images/tabs/home-active.png -------------------------------------------------------------------------------- /example/src/images/tabs/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinajs/mina-webpack/954761f689772903fd7b2d3f83d1493435818076/example/src/images/tabs/home.png -------------------------------------------------------------------------------- /example/src/packages/a/pages/home.mina: -------------------------------------------------------------------------------- 1 | 7 | 8 | 11 | 12 | 13 | 16 | -------------------------------------------------------------------------------- /example/src/pages/home.mina: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "usingComponents": { 4 | "tina-logo": "~@tinajs/tina-logo.mina", 5 | "circular": "../components/circular.mina", 6 | "foobar": "/components/foobar.mina", 7 | "classical": "../components/classical", 8 | "i-button": "~iview-weapp/dist/button/index", 9 | "van-button": "~@vant/weapp/lib/button/index", 10 | } 11 | } 12 | 13 | 14 | 28 | 29 | 41 | 42 | 58 | -------------------------------------------------------------------------------- /example/src/pages/message.mina: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | -------------------------------------------------------------------------------- /example/src/template/greeting.wxml: -------------------------------------------------------------------------------- 1 | {{ greeting() }} 2 | 3 | -------------------------------------------------------------------------------- /example/src/utils/dependency.js: -------------------------------------------------------------------------------- 1 | console.log('\u2665') 2 | -------------------------------------------------------------------------------- /example/src/wxs/datetime/now.wxs: -------------------------------------------------------------------------------- 1 | var padding = require('../string/padding.wxs') 2 | 3 | var now = getDate(); 4 | 5 | var year = now.getFullYear(); 6 | var month = padding(2)(now.getMonth() + 1); 7 | var date = padding(2)(now.getDate()); 8 | var hours = padding(2)(now.getHours()); 9 | var minutes = padding(2)(now.getMinutes()); 10 | var seconds = padding(2)(now.getSeconds()); 11 | 12 | module.exports = year + '-' + month + '-' + date + ' ' + hours + ':' + minutes + ':' + seconds; 13 | -------------------------------------------------------------------------------- /example/src/wxs/greeting.wxs: -------------------------------------------------------------------------------- 1 | function random (array) { 2 | return array[Math.floor(Math.random() * array.length)] 3 | } 4 | 5 | var GREETING = [ 6 | 'Hi', 7 | 'Glad to see you', 8 | 'How was your day', 9 | ] 10 | 11 | module.exports = function greeting () { 12 | return random(GREETING) 13 | } 14 | -------------------------------------------------------------------------------- /example/src/wxs/string/padding.wxs: -------------------------------------------------------------------------------- 1 | var padding = function (digits) { 2 | return function pad (number) { 3 | var ceil = Math.pow(10, digits) + number; 4 | return ceil.toString().slice(1); 5 | }; 6 | }; 7 | 8 | module.exports = padding 9 | -------------------------------------------------------------------------------- /example/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { resolve } = require('path') 2 | const webpack = require('webpack') 3 | const MinaEntryPlugin = require('@tinajs/mina-entry-webpack-plugin') 4 | const MinaRuntimePlugin = require('@tinajs/mina-runtime-webpack-plugin') 5 | 6 | const isProduction = process.env.NODE_ENV === 'production' 7 | 8 | const loaders = { 9 | script: 'babel-loader', 10 | style: { 11 | loader: 'postcss-loader', 12 | options: { 13 | config: { 14 | path: resolve('./postcss.config.js'), 15 | }, 16 | }, 17 | }, 18 | } 19 | 20 | module.exports = { 21 | context: resolve('src'), 22 | entry: './app.mina', 23 | output: { 24 | path: resolve(__dirname, 'dist'), 25 | filename: '[name]', 26 | publicPath: '/', 27 | globalObject: 'wx', 28 | }, 29 | module: { 30 | rules: [ 31 | { 32 | test: /\.mina$/, 33 | exclude: /node_modules/, 34 | use: [ 35 | { 36 | loader: '@tinajs/mina-loader', 37 | options: { 38 | loaders, 39 | }, 40 | }, 41 | ], 42 | }, 43 | { 44 | test: /\.mina$/, 45 | include: /node_modules/, 46 | use: '@tinajs/mina-loader', 47 | }, 48 | { 49 | test: /\.js$/, 50 | exclude: /node_modules/, 51 | use: loaders.script, 52 | }, 53 | { 54 | test: /\.(css|wxss)$/, 55 | exclude: /node_modules/, 56 | use: loaders.style, 57 | }, 58 | { 59 | test: /\.(png|jpg|jpeg|gif|svg)$/, 60 | use: { 61 | loader: 'file-loader', 62 | options: { 63 | name: 'assets/[name].[hash:6].[ext]', 64 | }, 65 | }, 66 | }, 67 | { 68 | test: /\.wxs$/, 69 | use: [ 70 | { 71 | loader: '@tinajs/wxs-loader', 72 | options: { 73 | name: 'wxs/[path]/[name].[hash:6].[ext]', 74 | context: resolve('src/wxs'), 75 | }, 76 | }, 77 | ], 78 | }, 79 | { 80 | test: /\.wxml$/, 81 | use: [ 82 | { 83 | loader: 'relative-file-loader', 84 | options: { 85 | name: 'wxml/[name].[hash:6].[ext]', 86 | }, 87 | }, 88 | { 89 | loader: '@tinajs/wxml-loader', 90 | options: { 91 | raw: true, 92 | enforceRelativePath: true, 93 | root: resolve('src'), 94 | }, 95 | }, 96 | ], 97 | }, 98 | ], 99 | }, 100 | resolve: { 101 | symlinks: true, 102 | }, 103 | plugins: [ 104 | new webpack.EnvironmentPlugin({ 105 | NODE_ENV: 'development', 106 | DEBUG: false, 107 | }), 108 | new MinaEntryPlugin({ 109 | map: entry => ['es6-promise/dist/es6-promise.auto.js', entry], 110 | }), 111 | new MinaRuntimePlugin({ 112 | runtime: './runtime.js', 113 | }), 114 | ], 115 | optimization: { 116 | splitChunks: { 117 | chunks: 'all', 118 | name: 'common.js', 119 | minChunks: 2, 120 | minSize: 0, 121 | }, 122 | runtimeChunk: { 123 | name: 'runtime.js', 124 | }, 125 | }, 126 | mode: isProduction ? 'production' : 'none', 127 | } 128 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "lerna": "3.20.2", 3 | "packages": ["packages/*", "example"], 4 | "version": "independent" 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "config": { 4 | "commitizen": { 5 | "path": "cz-conventional-changelog" 6 | } 7 | }, 8 | "devDependencies": { 9 | "husky": "^4.2.3", 10 | "lerna": "^6.4.1" 11 | }, 12 | "scripts": {}, 13 | "dependencies": { 14 | "debug": "^4.1.1" 15 | }, 16 | "husky": { 17 | "hooks": { 18 | "pre-commit": "lerna run --concurrency 1 --stream precommit" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/mina-entry-webpack-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ 2 | -------------------------------------------------------------------------------- /packages/mina-entry-webpack-plugin/.lintstagedrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "linters": { 3 | "*.{md,js,json}": ["prettier --write", "git add"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/mina-entry-webpack-plugin/.prettierrc.js: -------------------------------------------------------------------------------- 1 | // @see https://prettier.io/docs/en/options.html 2 | module.exports = { 3 | semi: false, 4 | singleQuote: true, 5 | trailingComma: 'es5', 6 | } 7 | -------------------------------------------------------------------------------- /packages/mina-entry-webpack-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /packages/mina-entry-webpack-plugin/README.md: -------------------------------------------------------------------------------- 1 | # mina-entry-webpack-plugin 2 | 3 | > Automaticly generates entries-list from mina files for [Webpack](https://webpack.js.org/) 4 | 5 | [![npm](https://img.shields.io/npm/v/@tinajs/mina-entry-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/mina-entry-webpack-plugin) 6 | [![npm](https://img.shields.io/npm/dw/@tinajs/mina-entry-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/@tinajs/mina-entry-webpack-plugin) 7 | [![license](https://img.shields.io/npm/l/@tinajs/mina-entry-webpack-plugin.svg?style=flat-square)](./LICENSE) 8 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 9 | 10 | ## Installation 11 | 12 | ```bash 13 | npm i --save-dev @tinajs/mina-entry-webpack-plugin 14 | ``` 15 | 16 | ## Usage 17 | 18 | ```javascript 19 | /** 20 | * webpack.config.js 21 | */ 22 | const webpack = require('webpack') 23 | const MinaEntryPlugin = require('@tinajs/mina-entry-webpack-plugin') 24 | const resolve = require('path').resolve 25 | 26 | // implement yourself if necessary 27 | const CustomFileTypeConfigReader = require('./custom-file-type-config-loader') 28 | 29 | module.exports = { 30 | context: resolve('src'), 31 | entry: './app.mina', 32 | output: { 33 | path: resolve('dist'), 34 | filename: '[name]', 35 | publicPath: '/', 36 | }, 37 | module: { 38 | rules: [ 39 | { 40 | test: /\.mina$/, 41 | use: { 42 | loader: '@tinajs/mina-loader', 43 | }, 44 | }, 45 | ], 46 | }, 47 | plugins: [ 48 | new MinaEntryPlugin({ 49 | map: (entry) => ['es6-promise/dist/es6-promise.auto.js', entry], 50 | rules: [{ 51 | { 52 | pattern: '**/*.custom-file-type', 53 | reader: CustomFileTypeConfigReader, 54 | }, 55 | }], 56 | }), 57 | ], 58 | } 59 | ``` 60 | 61 | For the best particle, you might also be interested in [mina-webpack](https://github.com/tinajs/mina-webpack/). 62 | 63 | ## Options 64 | 65 | | Name | Default | Description | 66 | | ------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | 67 | | map | (e) => e | Mapper function for each entry. Useful for adding polyfill scripts. | 68 | | rules | [] | Rules of custom config readers. See https://github.com/tinajs/mina-webpack/blob/master/packages/mina-loader/test/mina-entry-plugin.js#L204-L264 for examples | 69 | | rules[].pattern | '' | [Pattern, using glob expressions](https://www.npmjs.com/package/minimatch) | 70 | | rules[].reader | ConfigReader | Custom config reader, should inherit from [ConfigReader](./lib/interfaces/config-reader.js) and implement its `getConfig` interface | 71 | | extensions | ... | The extension names of each block for the separation (classical) files. | 72 | | extensions.template | `['.wxml']` | The extension name of the `