New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

weex-loader

Package Overview
Dependencies
Maintainers
3
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

weex-loader

a webpack loader for weex

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
121
increased by80.6%
Maintainers
3
Weekly downloads
 
Created
Source

Weex Loader

A webpack loader for Weex.

Install

npm install weex-loader --save

Feature

  1. Can load .we file.
  2. Can load parted files(.js/.css/.tpl) instead of one .we file.
  3. Can chain any loader you want when write parted files.
  4. Can require a CommonJS module.
  5. Can specify the name of a component.

Usage

How to load a .we file.

make a webpack config

var path = require('path');
var webpack = require('webpack');
var loader = require('weex-loader');

module.exports = {
  entry: './test/main.we?entry=true',
  output: {
    path: './test/actual',
    filename: 'main.js'
  },
  module: {
    loaders: [
      {
        test: /\.we(\?[^?]+)?$/,
        loader: 'weex'
      }
    ]
  }
};

How to write parted files

write .js/.css/.tpl anywhere

main.js as script

module.exports = {
    data: {
        text: 'Hello World'
    }
}

module.exports.style = require('./main.css');
module.exports.template = require('./main.tpl');

main.css as style

.h1 {
    font-size: 60px;
    color: red;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 20px;
    padding-right: 20px;
}

main.tpl as template

<container>
    <text class="h1">{{text}}</text>
</container>

Then change the entry to main.js in webpack.config.js

add some loader in webpack config

loader for script

  {
    test: /\.js(\?[^?]+)?$/,
    loader: 'weex?type=script'
  }

loader for style

  {
    test: /\.css(\?[^?]+)?$/, 
    loader: 'weex?type=style'
  }

loader for template

  {
    test: /\.tpl(\?[^?]+)?$/, 
    loader: 'weex?type=tpl'
  }

How to require a CommonJS module

  1. first, require a path/to/module.js in script like var _ = require('lodash').
  2. then use it in script.

How to embed a composed component

  1. first, require a path/to/component.js in script like require('./sub.js').
  2. second, use it in template like <sub></sub>.

How to specify the name of a component

  1. By default, the name is the basename without extname of component path.
  2. Give a name query in require request, like require('./sub.js?name="goto"')
  3. use the name in template like <goto></goto>.

Chain your favorite loader

For examples:

write ES2015

Only your need is chain babel-loader before weex-loader.

  {
    test: /\.js(\?[^?]+)?$/,
    loader: 'weex?type=script!babel?presets[]=es2015'
  }

write SCSS

Only your need is chain scss loader before weex-loader.

  {
    test: /\.scss(\?[^?]+)?$/, 
    loader: 'weex?type=style!scss'
  }

Test

npm run test

will run mocha testing

npm run serve

then open localhost:12581 on chrome, will run web testing

Keywords

FAQs

Package last updated on 15 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc