Giter Site home page Giter Site logo

mina-webpack's Introduction

mina-webpack

Mina single-file-component meets Webpack

Build Status PRs Welcome FOSSA Status

Get Started

We recommend you to get started with template-mina:

npm i -g sao

sao mina my-app
cd my-app
npm start

And see how to use with TinaJS

Packages included

Manual Installation

npm i --save-dev \
  @tinajs/mina-entry-webpack-plugin \
  @tinajs/mina-runtime-webpack-plugin \
  @tinajs/mina-loader \
  @tinajs/wxs-loader

Simplest Usage

webpack.config.js:

const webpack = require("webpack");
const MinaEntryPlugin = require("@tinajs/mina-entry-webpack-plugin");
const MinaRuntimePlugin = require("@tinajs/mina-runtime-webpack-plugin");
const resolve = require("path").resolve;

module.exports = {
  context: resolve("src"),
  entry: "./app.mina",
  output: {
    path: resolve("dist"),
    filename: "[name]",
    publicPath: "/",
    globalObject: "wx"
  },
  module: {
    rules: [
      {
        test: /\.mina$/,
        use: {
          loader: "@tinajs/mina-loader",
          options: {
            loaders: {
              script: "babel-loader"
            }
          }
        }
      },
      {
        test: /\.wxs$/,
        use: [
          {
            loader: '@tinajs/wxs-loader',
            options: {
              name: 'wxs/[name].[hash:6].[ext]',
            },
          },
        ],
      },
    ]
  },
  plugins: [
    new MinaEntryPlugin({
      map: entry => ["es6-promise/dist/es6-promise.auto.js", entry]
    }),
    new MinaRuntimePlugin()
  ],
  optimization: {
    splitChunks: {
      chunks: 'all',
      name: "common.js",
      minChunks: 2,
      minSize: 0
    },
    runtimeChunk: {
      name: "runtime.js"
    }
  },
  mode: "none"
};

app.mina:

<config>
{
  "pages": [
    "page.mina"
  ]
}
</config>

<script>
require('./dependency.js')
App({
  onLaunch () {
    console.log(say({ text: 'Hello from App!' }))
  }
})
</script>

page.mina:

<config>
{
  "window":{
    "navigationBarTitleText": "Hello, World!"
  }
}
</config>

<style>
.blue {
  color: #00f;
}
</style>

<template>
  <view>
    <text class="blue">{{ msg }}</text>
  </view>
</template>

<script>
require('./dependency.js')
Page({
  onLoad () {
    this.setData({
      msg: 'Hello from Page!',
    })
  },
})
</script>

Examples

Related Projects

Best to use with

Scaffolds

Other package compiler (also alternatives)

Got inspiration from

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.