ホームページ  >  記事  >  ウェブフロントエンド  >  Polymer_html/css_WEB-ITnose に関する予備調査

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

WBOY
WBOYオリジナル
2016-06-24 11:23:101161ブラウズ

最近、いくつかのモジュラー ソリューションを探しました。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 をサポートします。テストで問題がなければ、問題なく使用できます。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。