Преглед на файлове

simplify examples setup

Evan You преди 8 години
родител
ревизия
069109bf6a

+ 0 - 0
examples/chat/main.js → examples/chat/app.js


+ 2 - 1
examples/chat/index.html

@@ -7,6 +7,7 @@
   </head>
   <body>
     <div id="app"></div>
-    <script src="build.js"></script>
+    <script src="/__build__/shared.js"></script>
+    <script src="/__build__/chat.js"></script>
   </body>
 </html>

+ 0 - 0
examples/counter-hot/main.js → examples/counter-hot/app.js


+ 3 - 1
examples/counter-hot/index.html

@@ -3,9 +3,11 @@
   <head>
     <meta charset="utf-8">
     <title>vuex counter example</title>
+    <link rel="stylesheet" href="/global.css">
   </head>
   <body>
     <div id="app"></div>
-    <script src="build.js"></script>
+    <script src="/__build__/shared.js"></script>
+    <script src="/__build__/counter-hot.js"></script>
   </body>
 </html>

+ 0 - 0
examples/counter/main.js → examples/counter/app.js


+ 3 - 1
examples/counter/index.html

@@ -3,9 +3,11 @@
   <head>
     <meta charset="utf-8">
     <title>vuex counter example</title>
+    <link rel="stylesheet" href="/global.css">
   </head>
   <body>
     <div id="app"></div>
-    <script src="build.js"></script>
+    <script src="/__build__/shared.js"></script>
+    <script src="/__build__/counter.js"></script>
   </body>
 </html>

+ 18 - 0
examples/global.css

@@ -0,0 +1,18 @@
+html, body {
+  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
+  color: #2c3e50;
+}
+
+ul {
+  line-height: 1.5em;
+  padding-left: 1.5em;
+}
+
+a {
+  color: #7f8c8d;
+  text-decoration: none;
+}
+
+a:hover {
+  color: #4fc08d;
+}

+ 18 - 0
examples/index.html

@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>Vuex Examples</title>
+    <link rel="stylesheet" href="/global.css">
+  </head>
+  <body style="padding: 0 20px">
+    <h1>Vuex Examples</h1>
+    <ul>
+      <li><a href="counter">Counter</a></li>
+      <li><a href="counter-hot">Counter with Hot Reload</a></li>
+      <li><a href="shopping-cart">Shopping Cart</a></li>
+      <li><a href="todomvc">TodoMVC</a></li>
+      <li><a href="chat">FluxChat</a></li>
+    </ul>
+  </body>
+</html>

+ 0 - 0
examples/shopping-cart/main.js → examples/shopping-cart/app.js


+ 3 - 1
examples/shopping-cart/index.html

@@ -3,9 +3,11 @@
   <head>
     <meta charset="utf-8">
     <title>vuex shopping cart example</title>
+    <link rel="stylesheet" href="/global.css">
   </head>
   <body>
     <div id="app"></div>
-    <script src="build.js"></script>
+    <script src="/__build__/shared.js"></script>
+    <script src="/__build__/shopping-cart.js"></script>
   </body>
 </html>

+ 0 - 0
examples/todomvc/main.js → examples/todomvc/app.js


+ 2 - 1
examples/todomvc/index.html

@@ -6,6 +6,7 @@
   </head>
   <body>
     <div id="app"></div>
-    <script src="build.js"></script>
+    <script src="/__build__/shared.js"></script>
+    <script src="/__build__/todomvc.js"></script>
   </body>
 </html>

+ 0 - 40
examples/webpack.build-all.config.js

@@ -1,40 +0,0 @@
-var path = require('path')
-
-var examples = [
-  'chat',
-  'counter',
-  'counter-hot',
-  'shopping-cart',
-  'todomvc'
-]
-
-var entry = {}
-examples.forEach(function (name) {
-  entry[name] = ['./examples/' + name + '/main.js']
-})
-
-module.exports = {
-  entry: entry,
-  output: {
-    path: __dirname,
-    filename: '[name]/build.js'
-  },
-  resolve: {
-    alias: {
-      vuex: path.resolve(__dirname, '../build/dev-entry')
-    }
-  },
-  module: {
-    loaders: [
-      {
-        test: /\.js$/,
-        loader: 'babel',
-        exclude: /node_modules|vue\/dist|vue-hot-reload-api|vue-loader/
-      },
-      {
-        test: /\.vue$/,
-        loader: 'vue'
-      }
-    ]
-  }
-}

+ 46 - 0
examples/webpack.config.js

@@ -0,0 +1,46 @@
+const fs = require('fs')
+const path = require('path')
+const webpack = require('webpack')
+
+module.exports = {
+
+  devtool: 'inline-source-map',
+
+  entry: fs.readdirSync(__dirname).reduce((entries, dir) => {
+    const fullDir = path.join(__dirname, dir)
+    const entry = path.join(fullDir, 'app.js')
+    if (fs.statSync(fullDir).isDirectory() && fs.existsSync(entry)) {
+      entries[dir] = entry
+    }
+
+    return entries
+  }, {}),
+
+  output: {
+    path: path.join(__dirname, '__build__'),
+    filename: '[name].js',
+    chunkFilename: '[id].chunk.js',
+    publicPath: '/__build__/'
+  },
+
+  module: {
+    loaders: [
+      { test: /\.js$/, exclude: /node_modules/, loader: 'babel' },
+      { test: /\.vue$/, loader: 'vue' }
+    ]
+  },
+
+  resolve: {
+    alias: {
+      vuex: path.resolve(__dirname, '../build/dev-entry')
+    }
+  },
+
+  plugins: [
+    new webpack.optimize.CommonsChunkPlugin('shared.js'),
+    new webpack.DefinePlugin({
+      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
+    })
+  ]
+
+}

+ 0 - 28
examples/webpack.shared.config.js

@@ -1,28 +0,0 @@
-var path = require('path')
-
-module.exports = {
-  entry: './main.js',
-  output: {
-    path: process.cwd(),
-    filename: 'build.js'
-  },
-  resolve: {
-    alias: {
-      vuex: path.resolve(__dirname, '../build/dev-entry')
-    }
-  },
-  module: {
-    loaders: [
-      {
-        test: /\.js$/,
-        loader: 'babel',
-        exclude: /node_modules|vue\/dist|vue-hot-reload-api|vue-loader/
-      },
-      {
-        test: /\.vue$/,
-        loader: 'vue'
-      }
-    ]
-  },
-  devtool: '#source-map'
-}

+ 5 - 10
package.json

@@ -9,19 +9,14 @@
     "logger.js"
   ],
   "scripts": {
-    "counter": "cd examples/counter && webpack-dev-server --inline --hot --config ../webpack.shared.config.js",
-    "counter-hot": "cd examples/counter-hot && webpack-dev-server --inline --hot --config ../webpack.shared.config.js",
-    "todomvc": "cd examples/todomvc && webpack-dev-server --inline --hot --config ../webpack.shared.config.js",
-    "cart": "cd examples/shopping-cart && webpack-dev-server --inline --hot --config ../webpack.shared.config.js",
-    "chat": "cd examples/chat && webpack-dev-server --inline --hot --config ../webpack.shared.config.js",
-    "build": "node build/build.js",
-    "build-examples": "BABEL_ENV=development webpack --config examples/webpack.build-all.config.js",
+    "dev": "cd examples && webpack-dev-server --inline --hot --no-info",
     "test": "eslint src && npm run test:unit && npm run test:e2e",
-    "test:unit": "cross-env BABEL_ENV=development jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
+    "test:unit": "jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
     "test:e2e": "npm run build-examples && casperjs test --concise ./test/e2e",
+    "build": "node build/build.js",
+    "release": "bash build/release.sh",
     "docs": "cd docs && gitbook serve",
-    "deploy-docs": "cd docs && ./deploy.sh",
-    "release": "bash build/release.sh"
+    "docs:deploy": "cd docs && ./deploy.sh"
   },
   "repository": {
     "type": "git",