Polymer_html/css_WEB-ITnose に関する予備調査

WBOY
リリース: 2016-06-24 11:23:10
オリジナル
1172 人が閲覧しました

最近、いくつかのモジュラー ソリューションを探しました。Posthtml はまだあまり成熟しておらず、CSS モジュールを React と一緒に使用する必要があるため、ポリマーを試してみました。

ポリマーは Web コンポーネント仕様に基づいており、hello-world-polymer を使用するとポリマーにすぐに慣れることができます。

ポリマーモジュールの html、css、js はすべて一緒に書かれています。 hello-word.html コードは次のとおりです

<!-- Imports polymer --><link rel="import" href="../../polymer/polymer.html"><!-- Defines element markup --><dom-module id="hello-world">    <template>        <p>Hello <strong>{{who}}</strong> :)</p>    </template></dom-module><!-- Registers custom element --><script>Polymer({    is: 'hello-world',    properties: {        who: {            type: String,            value: 'World'        }    }});</script>
ログイン後にコピー

モジュールを定義した後、index.html ファイルにモジュールを導入し、< を使用します。 ;hello-world> タグ はい、このタグ名はモジュール内の ID と一致します。

<!doctype html><html><head>    <meta charset="utf-8">    <title><hello-world></title>    <!-- Imports polyfill -->    <script src="../webcomponentsjs/webcomponents-lite.min.js"></script>    <!-- Imports custom element -->    <link rel="import" href="build/hello-world.html"></head><body>    <!-- Runs custom element -->    <hello-world who="world"></hello-world></body></html>
ログイン後にコピー

複数のモジュールは問題ありません。新しい hello-module.html を作成し、少しスタイルを付けます

<!-- Imports polymer --><link rel="import" href="../../polymer/polymer.html"><!-- Defines element markup --><dom-module id="hello-module">  <style>    p{      color: red;      display: flex;    }    strong{      color: black;    }  </style>    <template>        <p>Hello <strong>{{who}}</strong> :)</p>    </template></dom-module><!-- Registers custom element --><script>Polymer({    is: 'hello-module',    properties: {        who: {            type: String,            value: 'Module'        }    }});</script>
ログイン後にコピー

を、index.html に導入します。Polymer はすでに次のように名前を追加しています。スペースとスタイルは互いに影響しません。

しかし、一部の css3 属性についてはどうでしょうか。autoprefixer または cssnext も必要です。 3 つのプラグインのサポートが必要です。コマンド ラインで

<!doctype html><html><head>    <meta charset="utf-8">    <title><hello-world></title>    <!-- Imports polyfill -->    <script src="../webcomponentsjs/webcomponents-lite.min.js"></script>    <!-- Imports custom element -->    <link rel="import" href="build/hello-module.html">    <link rel="import" href="build/hello-world.html"></head><body>    <!-- Runs custom element -->    <hello-module who="module"></hello-module>    <hello-world who="world"></hello-world></body></html>
ログイン後にコピー

と入力し、gulpfile.js ファイルを変更します

npm i --save gulp-posthtml posthtml-postcss postcss-cssnext
ログイン後にコピー

コマンド ラインで gulp を入力すると、リアルタイムでコンパイルされます。生成されたモジュールコードは以下の通りです

var gulp = require('gulp'),    postcssPlugins = [require('postcss-cssnext')({ browsers: ['last 10 versions'] })]gulp.task('html', function() {    var posthtml = require('gulp-posthtml');    return gulp.src('modules/*.html')        .pipe(posthtml([ require('posthtml-postcss')(postcssPlugins) ]/*, options */))        .pipe(gulp.dest('build/'));});gulp.task('watch', function() {    gulp.watch("modules/**.html",["html"]);});gulp.task('default', ['html', 'watch']);
ログイン後にコピー

テスト後、ポリマーは Android 4.1 をサポートします。テストで問題がなければ、問題なく使用できます。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!