diff --git a/micro-app/app.json b/micro-app/app.json index f381d29..1c0b234 100644 --- a/micro-app/app.json +++ b/micro-app/app.json @@ -1,13 +1,21 @@ { - "pages":[ + "pages": [ "pages/index/index", "pages/logs/logs", "pages/example/example" ], - "window":{ - "backgroundTextStyle":"light", + "subPackages": [ + { + "root": "packageMore", + "pages": [ + "pages/conclude/conclude" + ] + } + ], + "window": { + "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "WeChat", - "navigationBarTextStyle":"black" + "navigationBarTextStyle": "black" } -} +} \ No newline at end of file diff --git a/micro-app/components/week/week.js b/micro-app/components/week/week.js new file mode 100644 index 0000000..e79f068 --- /dev/null +++ b/micro-app/components/week/week.js @@ -0,0 +1,26 @@ +// components/week/week.js +Component({ + /** + * 组件的属性列表 + */ + properties: { + dateArray: { + type: Array, + value: [] + } + }, + + /** + * 组件的初始数据 + */ + data: { + privateData: {} + }, + + /** + * 组件的方法列表 + */ + methods: { + + } +}) diff --git a/micro-app/components/week/week.json b/micro-app/components/week/week.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/micro-app/components/week/week.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/micro-app/components/week/week.wxml b/micro-app/components/week/week.wxml new file mode 100644 index 0000000..4415dda --- /dev/null +++ b/micro-app/components/week/week.wxml @@ -0,0 +1,6 @@ + + +
+ week组件{{item.dateNum}} +
+
diff --git a/micro-app/components/week/week.wxss b/micro-app/components/week/week.wxss new file mode 100644 index 0000000..d977fe2 --- /dev/null +++ b/micro-app/components/week/week.wxss @@ -0,0 +1,15 @@ +/* components/week/week.wxss */ +.date-container { + height: 50px; + width: 100%; + display: flex; + justify-content: center; + align-items: center; +} +.date-item { + flex: 1; + text-align: center; +} +.date-num { + color: forestgreen +} \ No newline at end of file diff --git a/micro-app/packageMore/pages/conclude/conclude.js b/micro-app/packageMore/pages/conclude/conclude.js new file mode 100644 index 0000000..d646ec7 --- /dev/null +++ b/micro-app/packageMore/pages/conclude/conclude.js @@ -0,0 +1,66 @@ +// packageMore/pages/conclude.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + console.log('page conclude in packageMore is loaded') + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/micro-app/packageMore/pages/conclude/conclude.json b/micro-app/packageMore/pages/conclude/conclude.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/micro-app/packageMore/pages/conclude/conclude.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/micro-app/packageMore/pages/conclude/conclude.wxml b/micro-app/packageMore/pages/conclude/conclude.wxml new file mode 100644 index 0000000..29539a7 --- /dev/null +++ b/micro-app/packageMore/pages/conclude/conclude.wxml @@ -0,0 +1,2 @@ + +packageMore/pages/conclude.wxml diff --git a/micro-app/packageMore/pages/conclude/conclude.wxss b/micro-app/packageMore/pages/conclude/conclude.wxss new file mode 100644 index 0000000..9c1c63a --- /dev/null +++ b/micro-app/packageMore/pages/conclude/conclude.wxss @@ -0,0 +1 @@ +/* packageMore/pages/conclude.wxss */ \ No newline at end of file diff --git a/micro-app/pages/example/example.js b/micro-app/pages/example/example.js index b2368eb..750328d 100644 --- a/micro-app/pages/example/example.js +++ b/micro-app/pages/example/example.js @@ -1,7 +1,13 @@ const app = getApp() Page({ data: { - + dateArray: [] + }, + onLoad: function () { + console.log('example page loaded'); + this.setData({ + dateArray: [{ dateNum: 1 }, { dateNum: 2 }, { dateNum: 3 }] + }) }, showShareMenu: function (e) { wx.showShareMenu({ @@ -43,4 +49,9 @@ Page({ listenSwiper(e) { console.log('change swipe') }, + goToConcludePage() { + wx.navigateTo({ + url: '/packageMore/pages/conclude/conclude', + }) + } }) \ No newline at end of file diff --git a/micro-app/pages/example/example.json b/micro-app/pages/example/example.json index 9e26dfe..ce7ae8b 100644 --- a/micro-app/pages/example/example.json +++ b/micro-app/pages/example/example.json @@ -1 +1,5 @@ -{} \ No newline at end of file +{ + "usingComponents": { + "custom-week": "/components/week/week" + } +} \ No newline at end of file diff --git a/micro-app/pages/example/example.wxml b/micro-app/pages/example/example.wxml index 7504a11..2768cac 100644 --- a/micro-app/pages/example/example.wxml +++ b/micro-app/pages/example/example.wxml @@ -27,4 +27,8 @@ 66666 + + + + \ No newline at end of file diff --git a/micro-app/pages/index/index.js b/micro-app/pages/index/index.js index 3402276..4ba8282 100644 --- a/micro-app/pages/index/index.js +++ b/micro-app/pages/index/index.js @@ -16,6 +16,7 @@ Page({ }) }, onLoad: function () { + console.log('index page loaded'); if (app.globalData.userInfo) { this.setData({ userInfo: app.globalData.userInfo, diff --git a/micro-app/pages/index/index.wxml b/micro-app/pages/index/index.wxml index 6c6d82e..db02faa 100644 --- a/micro-app/pages/index/index.wxml +++ b/micro-app/pages/index/index.wxml @@ -13,4 +13,5 @@ +

hello world

diff --git a/micro-app/pages/logs/logs.js b/micro-app/pages/logs/logs.js index b2b967d..8537b6d 100644 --- a/micro-app/pages/logs/logs.js +++ b/micro-app/pages/logs/logs.js @@ -6,6 +6,7 @@ Page({ logs: [] }, onLoad: function () { + console.log('log page loaded'); this.setData({ logs: (wx.getStorageSync('logs') || []).map(log => { return util.formatTime(new Date(log)) diff --git a/webpack4/.babelrc b/webpack4/.babelrc new file mode 100644 index 0000000..13f0e47 --- /dev/null +++ b/webpack4/.babelrc @@ -0,0 +1,14 @@ +{ + "presets": [ + ["env", { "modules": false }], + "stage-2" + ], + "plugins": ["transform-runtime"], + "comments": false, + "env": { + "test": { + "presets": ["env", "stage-2"], + "plugins": [ "istanbul" ] + } + } +} diff --git a/webpack4/README.md b/webpack4/README.md new file mode 100755 index 0000000..bc45f94 --- /dev/null +++ b/webpack4/README.md @@ -0,0 +1,22 @@ +# vue2 + +> A Vue.js project + +## Build Setup + +``` bash +# install dependencies +npm install + +# serve with hot reload at localhost:8080 +npm run dev + +# build for production with minification +npm run build + +# build for production and view the bundle analyzer report +npm run build --report + +``` + +For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). diff --git a/webpack4/build/build.js b/webpack4/build/build.js new file mode 100755 index 0000000..30f036a --- /dev/null +++ b/webpack4/build/build.js @@ -0,0 +1,41 @@ +'use strict' +require('./check-versions')() + +process.env.NODE_ENV = 'production' + +const ora = require('ora') +const rm = require('rimraf') +const path = require('path') +const chalk = require('chalk') +const webpack = require('webpack') +const config = require('../config') +const webpackConfig = require('./webpack.prod.conf') + +const spinner = ora('building for production...') +spinner.start() + +rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { + if (err) throw err + webpack(webpackConfig, function (err, stats) { + spinner.stop() + if (err) throw err + process.stdout.write(stats.toString({ + colors: true, + modules: false, + children: false, + chunks: false, + chunkModules: false + }) + '\n\n') + + if (stats.hasErrors()) { + console.log(chalk.red(' Build failed with errors.\n')) + process.exit(1) + } + + console.log(chalk.cyan(' Build complete.\n')) + console.log(chalk.yellow( + ' Tip: built files are meant to be served over an HTTP server.\n' + + ' Opening index.html over file:// won\'t work.\n' + )) + }) +}) diff --git a/webpack4/build/check-versions.js b/webpack4/build/check-versions.js new file mode 100755 index 0000000..ca407bb --- /dev/null +++ b/webpack4/build/check-versions.js @@ -0,0 +1,49 @@ +'use strict' +const chalk = require('chalk') +const semver = require('semver') +const packageConfig = require('../package.json') +const shell = require('shelljs') +function exec (cmd) { + return require('child_process').execSync(cmd).toString().trim() +} + +const versionRequirements = [ + { + name: 'node', + currentVersion: semver.clean(process.version), + versionRequirement: packageConfig.engines.node + } +] + +if (shell.which('npm')) { + versionRequirements.push({ + name: 'npm', + currentVersion: exec('npm --version'), + versionRequirement: packageConfig.engines.npm + }) +} + +module.exports = function () { + const warnings = [] + for (let i = 0; i < versionRequirements.length; i++) { + const mod = versionRequirements[i] + if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { + warnings.push(mod.name + ': ' + + chalk.red(mod.currentVersion) + ' should be ' + + chalk.green(mod.versionRequirement) + ) + } + } + + if (warnings.length) { + console.log('') + console.log(chalk.yellow('To use this template, you must update following to modules:')) + console.log() + for (let i = 0; i < warnings.length; i++) { + const warning = warnings[i] + console.log(' ' + warning) + } + console.log() + process.exit(1) + } +} diff --git a/webpack4/build/dev-client.js b/webpack4/build/dev-client.js new file mode 100755 index 0000000..2f75dd5 --- /dev/null +++ b/webpack4/build/dev-client.js @@ -0,0 +1,10 @@ +/* eslint-disable */ +'use strict' +require('eventsource-polyfill') +var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') + +hotClient.subscribe(function (event) { + if (event.action === 'reload') { + window.location.reload() + } +}) diff --git a/webpack4/build/dev-server.js b/webpack4/build/dev-server.js new file mode 100755 index 0000000..bcb5c07 --- /dev/null +++ b/webpack4/build/dev-server.js @@ -0,0 +1,107 @@ +'use strict' +require('./check-versions')() + +const config = require('../config') +if (!process.env.NODE_ENV) { + process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) +} + +const opn = require('opn') +const path = require('path') +const express = require('express') +const webpack = require('webpack') +const proxyMiddleware = require('http-proxy-middleware') +const webpackConfig = (process.env.NODE_ENV === 'testing' || process.env.NODE_ENV === 'production') + ? require('./webpack.prod.conf') + : require('./webpack.dev.conf') + +// default port where dev server listens for incoming traffic +const port = process.env.PORT || config.dev.port +// automatically open browser, if not set will be false +const autoOpenBrowser = !!config.dev.autoOpenBrowser +// Define HTTP proxies to your custom API backend +// https://github.com/chimurai/http-proxy-middleware +const proxyTable = config.dev.proxyTable + +const app = express() +const compiler = webpack(webpackConfig) + +const devMiddleware = require('webpack-dev-middleware')(compiler, { + publicPath: webpackConfig.output.publicPath, + quiet: true +}) + +const hotMiddleware = require('webpack-hot-middleware')(compiler, { + log: false, + heartbeat: 2000 +}) +// force page reload when html-webpack-plugin template changes +// currently disabled until this is resolved: +// https://github.com/jantimon/html-webpack-plugin/issues/680 +// compiler.plugin('compilation', function (compilation) { +// compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { +// hotMiddleware.publish({ action: 'reload' }) +// cb() +// }) +// }) + +// enable hot-reload and state-preserving +// compilation error display +app.use(hotMiddleware) + +// proxy api requests +Object.keys(proxyTable).forEach(function (context) { + let options = proxyTable[context] + if (typeof options === 'string') { + options = { target: options } + } + app.use(proxyMiddleware(options.filter || context, options)) +}) + +// handle fallback for HTML5 history API +app.use(require('connect-history-api-fallback')()) + +// serve webpack bundle output +app.use(devMiddleware) + +// serve pure static assets +const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) +app.use(staticPath, express.static('./static')) + +const uri = 'http://localhost:' + port + +var _resolve +var _reject +var readyPromise = new Promise((resolve, reject) => { + _resolve = resolve + _reject = reject +}) + +var server +var portfinder = require('portfinder') +portfinder.basePort = port + +console.log('> Starting dev server...') +devMiddleware.waitUntilValid(() => { + portfinder.getPort((err, port) => { + if (err) { + _reject(err) + } + process.env.PORT = port + var uri = 'http://localhost:' + port + console.log('> Listening at ' + uri + '\n') + // when env is testing, don't need open it + if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { + opn(uri) + } + server = app.listen(port) + _resolve() + }) +}) + +module.exports = { + ready: readyPromise, + close: () => { + server.close() + } +} diff --git a/webpack4/build/utils.js b/webpack4/build/utils.js new file mode 100755 index 0000000..4ac71cb --- /dev/null +++ b/webpack4/build/utils.js @@ -0,0 +1,72 @@ +'use strict' +const path = require('path') +const config = require('../config') +const ExtractTextPlugin = require('extract-text-webpack-plugin') + +exports.assetsPath = function (_path) { + const assetsSubDirectory = process.env.NODE_ENV === 'production' + ? config.build.assetsSubDirectory + : config.dev.assetsSubDirectory + return path.posix.join(assetsSubDirectory, _path) +} + +exports.cssLoaders = function (options) { + options = options || {} + + const cssLoader = { + loader: 'css-loader', + options: { + minimize: process.env.NODE_ENV === 'production', + sourceMap: options.sourceMap + } + } + + // generate loader string to be used with extract text plugin + function generateLoaders (loader, loaderOptions) { + const loaders = [cssLoader] + if (loader) { + loaders.push({ + loader: loader + '-loader', + options: Object.assign({}, loaderOptions, { + sourceMap: options.sourceMap + }) + }) + } + + // Extract CSS when that option is specified + // (which is the case during production build) + if (options.extract) { + return ExtractTextPlugin.extract({ + use: loaders, + fallback: 'vue-style-loader' + }) + } else { + return ['vue-style-loader'].concat(loaders) + } + } + + // https://vue-loader.vuejs.org/en/configurations/extract-css.html + return { + css: generateLoaders(), + postcss: generateLoaders(), + less: generateLoaders('less'), + sass: generateLoaders('sass', { indentedSyntax: true }), + scss: generateLoaders('sass'), + stylus: generateLoaders('stylus'), + styl: generateLoaders('stylus') + } +} + +// Generate loaders for standalone style files (outside of .vue) +exports.styleLoaders = function (options) { + const output = [] + const loaders = exports.cssLoaders(options) + for (const extension in loaders) { + const loader = loaders[extension] + output.push({ + test: new RegExp('\\.' + extension + '$'), + use: loader + }) + } + return output +} diff --git a/webpack4/build/vue-loader.conf.js b/webpack4/build/vue-loader.conf.js new file mode 100755 index 0000000..eece58f --- /dev/null +++ b/webpack4/build/vue-loader.conf.js @@ -0,0 +1,19 @@ +'use strict' +const utils = require('./utils') +const config = require('../config') +const isProduction = process.env.NODE_ENV === 'production' + +module.exports = { + loaders: utils.cssLoaders({ + sourceMap: isProduction + ? config.build.productionSourceMap + : config.dev.cssSourceMap, + extract: isProduction + }), + transformToRequire: { + video: 'src', + source: 'src', + img: 'src', + image: 'xlink:href' + } +} diff --git a/webpack4/build/webpack.base.conf.js b/webpack4/build/webpack.base.conf.js new file mode 100755 index 0000000..5564461 --- /dev/null +++ b/webpack4/build/webpack.base.conf.js @@ -0,0 +1,67 @@ +'use strict' +const path = require('path') +const utils = require('./utils') +const config = require('../config') +const vueLoaderConfig = require('./vue-loader.conf') + +function resolve (dir) { + return path.join(__dirname, '..', dir) +} + +module.exports = { + entry: { + app: './src/main.js' + }, + output: { + path: config.build.assetsRoot, + filename: '[name].[hash].js', + publicPath: process.env.NODE_ENV === 'production' + ? config.build.assetsPublicPath + : config.dev.assetsPublicPath + }, + resolve: { + extensions: ['.js', '.vue', '.json'], + alias: { + 'vue$': 'vue/dist/vue.esm.js', + '@': resolve('src'), + } + }, + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue-loader', + options: vueLoaderConfig + }, + { + test: /\.js$/, + loader: 'babel-loader', + include: [resolve('src'), resolve('test')] + }, + { + test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, + loader: 'url-loader', + options: { + limit: 10000, + name: utils.assetsPath('img/[name].[hash:7].[ext]') + } + }, + { + test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, + loader: 'url-loader', + options: { + limit: 10000, + name: utils.assetsPath('media/[name].[hash:7].[ext]') + } + }, + { + test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, + loader: 'url-loader', + options: { + limit: 10000, + name: utils.assetsPath('fonts/[name].[hash:7].[ext]') + } + } + ] + } +} diff --git a/webpack4/build/webpack.dev.conf.js b/webpack4/build/webpack.dev.conf.js new file mode 100755 index 0000000..6f25d63 --- /dev/null +++ b/webpack4/build/webpack.dev.conf.js @@ -0,0 +1,36 @@ +'use strict' +const utils = require('./utils') +const webpack = require('webpack') +const config = require('../config') +const merge = require('webpack-merge') +const baseWebpackConfig = require('./webpack.base.conf') +const HtmlWebpackPlugin = require('html-webpack-plugin') +const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') + +// add hot-reload related code to entry chunks +Object.keys(baseWebpackConfig.entry).forEach(function (name) { + baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) +}) + +module.exports = merge(baseWebpackConfig, { + module: { + rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) + }, + // cheap-module-eval-source-map is faster for development + devtool: '#cheap-module-eval-source-map', + plugins: [ + new webpack.DefinePlugin({ + 'process.env': config.dev.env + }), + // https://github.com/glenjamin/webpack-hot-middleware#installation--usage + new webpack.HotModuleReplacementPlugin(), + new webpack.NoEmitOnErrorsPlugin(), + // https://github.com/ampedandwired/html-webpack-plugin + new HtmlWebpackPlugin({ + filename: 'index.html', + template: 'index.html', + inject: true + }), + new FriendlyErrorsPlugin() + ] +}) diff --git a/webpack4/build/webpack.prod.conf.js b/webpack4/build/webpack.prod.conf.js new file mode 100755 index 0000000..1b91741 --- /dev/null +++ b/webpack4/build/webpack.prod.conf.js @@ -0,0 +1,128 @@ +'use strict' +const path = require('path') +const utils = require('./utils') +const webpack = require('webpack') +const config = require('../config') +const merge = require('webpack-merge') +const baseWebpackConfig = require('./webpack.base.conf') +const CopyWebpackPlugin = require('copy-webpack-plugin') +const HtmlWebpackPlugin = require('html-webpack-plugin') +const ExtractTextPlugin = require('extract-text-webpack-plugin') +const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') + +const env = {{#if_or unit e2e}}process.env.NODE_ENV === 'testing' + ? require('../config/test.env') + : {{/if_or}}config.build.env + +const webpackConfig = merge(baseWebpackConfig, { + module: { + rules: utils.styleLoaders({ + sourceMap: config.build.productionSourceMap, + extract: true + }) + }, + devtool: config.build.productionSourceMap ? '#source-map' : false, + output: { + path: config.build.assetsRoot, + filename: utils.assetsPath('js/[name].[chunkhash].js'), + chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') + }, + plugins: [ + // http://vuejs.github.io/vue-loader/en/workflow/production.html + new webpack.DefinePlugin({ + 'process.env': env + }), + // UglifyJs do not support ES6+, you can also use babel-minify for better treeshaking: https://github.com/babel/minify + new webpack.optimize.UglifyJsPlugin({ + compress: { + warnings: false + }, + sourceMap: true + }), + // extract css into its own file + new ExtractTextPlugin({ + filename: utils.assetsPath('css/[name].[contenthash].css') + }), + // Compress extracted CSS. We are using this plugin so that possible + // duplicated CSS from different components can be deduped. + new OptimizeCSSPlugin({ + cssProcessorOptions: { + safe: true + } + }), + // generate dist index.html with correct asset hash for caching. + // you can customize output by editing /index.html + // see https://github.com/ampedandwired/html-webpack-plugin + new HtmlWebpackPlugin({ + filename: {{#if_or unit e2e}}process.env.NODE_ENV === 'testing' + ? 'index.html' + : {{/if_or}}config.build.index, + template: 'index.html', + inject: true, + minify: { + removeComments: true, + collapseWhitespace: true, + removeAttributeQuotes: true + // more options: + // https://github.com/kangax/html-minifier#options-quick-reference + }, + // necessary to consistently work with multiple chunks via CommonsChunkPlugin + chunksSortMode: 'dependency' + }), + // keep module.id stable when vender modules does not change + new webpack.HashedModuleIdsPlugin(), + // split vendor js into its own file + new webpack.optimize.CommonsChunkPlugin({ + name: 'vendor', + minChunks: function (module) { + // any required modules inside node_modules are extracted to vendor + return ( + module.resource && + /\.js$/.test(module.resource) && + module.resource.indexOf( + path.join(__dirname, '../node_modules') + ) === 0 + ) + } + }), + // extract webpack runtime and module manifest to its own file in order to + // prevent vendor hash from being updated whenever app bundle is updated + new webpack.optimize.CommonsChunkPlugin({ + name: 'manifest', + chunks: ['vendor'] + }), + // copy custom static assets + new CopyWebpackPlugin([ + { + from: path.resolve(__dirname, '../static'), + to: config.build.assetsSubDirectory, + ignore: ['.*'] + } + ]) + ] +}) + +if (config.build.productionGzip) { + const CompressionWebpackPlugin = require('compression-webpack-plugin') + + webpackConfig.plugins.push( + new CompressionWebpackPlugin({ + asset: '[path].gz[query]', + algorithm: 'gzip', + test: new RegExp( + '\\.(' + + config.build.productionGzipExtensions.join('|') + + ')$' + ), + threshold: 10240, + minRatio: 0.8 + }) + ) +} + +if (config.build.bundleAnalyzerReport) { + const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin + webpackConfig.plugins.push(new BundleAnalyzerPlugin()) +} + +module.exports = webpackConfig diff --git a/webpack4/build/webpack.test.conf.js b/webpack4/build/webpack.test.conf.js new file mode 100755 index 0000000..0d658d9 --- /dev/null +++ b/webpack4/build/webpack.test.conf.js @@ -0,0 +1,32 @@ +'use strict' +// This is the webpack config used for unit tests. + +const utils = require('./utils') +const webpack = require('webpack') +const merge = require('webpack-merge') +const baseWebpackConfig = require('./webpack.base.conf') + +const webpackConfig = merge(baseWebpackConfig, { + // use inline sourcemap for karma-sourcemap-loader + module: { + rules: utils.styleLoaders() + }, + devtool: '#inline-source-map', + resolveLoader: { + alias: { + // necessary to to make lang="scss" work in test when using vue-loader's ?inject option + // see discussion at https://github.com/vuejs/vue-loader/issues/724 + 'scss-loader': 'sass-loader' + } + }, + plugins: [ + new webpack.DefinePlugin({ + 'process.env': require('../config/test.env') + }) + ] +}) + +// no need for app entry during tests +delete webpackConfig.entry + +module.exports = webpackConfig diff --git a/webpack4/config/dev.env.js b/webpack4/config/dev.env.js new file mode 100755 index 0000000..1e22973 --- /dev/null +++ b/webpack4/config/dev.env.js @@ -0,0 +1,7 @@ +'use strict' +const merge = require('webpack-merge') +const prodEnv = require('./prod.env') + +module.exports = merge(prodEnv, { + NODE_ENV: '"development"' +}) diff --git a/webpack4/config/index.js b/webpack4/config/index.js new file mode 100755 index 0000000..9b91aaf --- /dev/null +++ b/webpack4/config/index.js @@ -0,0 +1,42 @@ + +'use strict' +// Template version: 1.1.1 +// see http://vuejs-templates.github.io/webpack for documentation. + +const path = require('path') + +module.exports = { + build: { + env: require('./prod.env'), + index: path.resolve(__dirname, '../dist/index.html'), + assetsRoot: path.resolve(__dirname, '../dist'), + assetsSubDirectory: 'static', + assetsPublicPath: '/', + productionSourceMap: true, + // Gzip off by default as many popular static hosts such as + // Surge or Netlify already gzip all static assets for you. + // Before setting to `true`, make sure to: + // npm install --save-dev compression-webpack-plugin + productionGzip: false, + productionGzipExtensions: ['js', 'css'], + // Run the build command with an extra argument to + // View the bundle analyzer report after build finishes: + // `npm run build --report` + // Set to `true` or `false` to always turn it on or off + bundleAnalyzerReport: process.env.npm_config_report + }, + dev: { + env: require('./dev.env'), + port: process.env.PORT || 8080, + autoOpenBrowser: true, + assetsSubDirectory: 'static', + assetsPublicPath: '/', + proxyTable: {}, + // CSS Sourcemaps off by default because relative paths are "buggy" + // with this option, according to the CSS-Loader README + // (https://github.com/webpack/css-loader#sourcemaps) + // In our experience, they generally work as expected, + // just be aware of this issue when enabling this option. + cssSourceMap: false + } +} diff --git a/webpack4/config/prod.env.js b/webpack4/config/prod.env.js new file mode 100755 index 0000000..a6f9976 --- /dev/null +++ b/webpack4/config/prod.env.js @@ -0,0 +1,4 @@ +'use strict' +module.exports = { + NODE_ENV: '"production"' +} diff --git a/webpack4/config/test.env.js b/webpack4/config/test.env.js new file mode 100755 index 0000000..c2824a3 --- /dev/null +++ b/webpack4/config/test.env.js @@ -0,0 +1,7 @@ +'use strict' +const merge = require('webpack-merge') +const devEnv = require('./dev.env') + +module.exports = merge(devEnv, { + NODE_ENV: '"testing"' +}) diff --git a/webpack4/index.html b/webpack4/index.html new file mode 100755 index 0000000..60edbcf --- /dev/null +++ b/webpack4/index.html @@ -0,0 +1,11 @@ + + + + + {{ name }} + + +
+ + + diff --git a/webpack4/npm-debug.log b/webpack4/npm-debug.log new file mode 100644 index 0000000..6cfec97 --- /dev/null +++ b/webpack4/npm-debug.log @@ -0,0 +1,48 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/Users/baidu/.nvm/versions/node/v6.11.3/bin/node', +1 verbose cli '/Users/baidu/.nvm/versions/node/v6.11.3/bin/npm', +1 verbose cli 'run', +1 verbose cli 'dev' ] +2 info using npm@3.10.10 +3 info using node@v6.11.3 +4 verbose run-script [ 'predev', 'dev', 'postdev' ] +5 info lifecycle vue2@1.0.0~predev: vue2@1.0.0 +6 silly lifecycle vue2@1.0.0~predev: no script for predev, continuing +7 info lifecycle vue2@1.0.0~dev: vue2@1.0.0 +8 verbose lifecycle vue2@1.0.0~dev: unsafe-perm in lifecycle true +9 verbose lifecycle vue2@1.0.0~dev: PATH: /Users/baidu/.nvm/versions/node/v6.11.3/lib/node_modules/npm/bin/node-gyp-bin:/Users/baidu/hwm/home/git/learning-notes/webpack-hmr/node_modules/.bin:/Users/baidu/.avn/bin:/Users/baidu/.nvm/versions/node/v6.11.3/bin:/Users/baidu/Library/Android/sdk/tools:/Users/baidu/Library/Android/sdk/platform-tools:/Users/baidu/hwm/MongoDB/mongodb-osx-x86_64-3.0.6/bin:/Applications/XAMPP/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/baidu/bin +10 verbose lifecycle vue2@1.0.0~dev: CWD: /Users/baidu/hwm/home/git/learning-notes/webpack-hmr +11 silly lifecycle vue2@1.0.0~dev: Args: [ '-c', 'node build/dev-server.js' ] +12 silly lifecycle vue2@1.0.0~dev: Returned: code: 1 signal: null +13 info lifecycle vue2@1.0.0~dev: Failed to exec dev script +14 verbose stack Error: vue2@1.0.0 dev: `node build/dev-server.js` +14 verbose stack Exit status 1 +14 verbose stack at EventEmitter. (/Users/baidu/.nvm/versions/node/v6.11.3/lib/node_modules/npm/lib/utils/lifecycle.js:255:16) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at EventEmitter.emit (events.js:191:7) +14 verbose stack at ChildProcess. (/Users/baidu/.nvm/versions/node/v6.11.3/lib/node_modules/npm/lib/utils/spawn.js:40:14) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at ChildProcess.emit (events.js:191:7) +14 verbose stack at maybeClose (internal/child_process.js:920:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5) +15 verbose pkgid vue2@1.0.0 +16 verbose cwd /Users/baidu/hwm/home/git/learning-notes/webpack-hmr +17 error Darwin 16.7.0 +18 error argv "/Users/baidu/.nvm/versions/node/v6.11.3/bin/node" "/Users/baidu/.nvm/versions/node/v6.11.3/bin/npm" "run" "dev" +19 error node v6.11.3 +20 error npm v3.10.10 +21 error code ELIFECYCLE +22 error vue2@1.0.0 dev: `node build/dev-server.js` +22 error Exit status 1 +23 error Failed at the vue2@1.0.0 dev script 'node build/dev-server.js'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the vue2 package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error node build/dev-server.js +23 error You can get information on how to open an issue for this project with: +23 error npm bugs vue2 +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls vue2 +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/webpack4/package.json b/webpack4/package.json new file mode 100755 index 0000000..0863c9e --- /dev/null +++ b/webpack4/package.json @@ -0,0 +1,65 @@ +{ + "name": "vue2", + "version": "1.0.0", + "description": "A Vue.js project", + "author": "huangwenming ", + "private": true, + "scripts": { + "dev": "node build/dev-server.js", + "start": "npm run dev", + "build": "node build/build.js" + }, + "dependencies": { + "vue": "^2.5.2", + "vue-router": "^3.0.1" + }, + "devDependencies": { + "autoprefixer": "^7.1.2", + "babel-core": "^6.22.1", + "babel-loader": "^7.1.1", + "babel-plugin-transform-runtime": "^6.22.0", + "babel-preset-env": "^1.3.2", + "babel-preset-stage-2": "^6.22.0", + "babel-register": "^6.22.0", + "chalk": "^2.0.1", + "connect-history-api-fallback": "^1.3.0", + "copy-webpack-plugin": "^4.0.1", + "css-loader": "^0.28.0", + "eslint": "^3.19.0", + "eslint-friendly-formatter": "^3.0.0", + "eslint-loader": "^1.7.1", + "eslint-plugin-html": "^3.0.0", + "eventsource-polyfill": "^0.9.6", + "express": "^4.14.1", + "extract-text-webpack-plugin": "^3.0.0", + "file-loader": "^1.1.4", + "friendly-errors-webpack-plugin": "^1.6.1", + "html-webpack-plugin": "^2.30.1", + "http-proxy-middleware": "^0.17.3", + "webpack-bundle-analyzer": "^2.9.0", + "semver": "^5.3.0", + "shelljs": "^0.7.6", + "opn": "^5.1.0", + "optimize-css-assets-webpack-plugin": "^3.2.0", + "ora": "^1.2.0", + "rimraf": "^2.6.0", + "url-loader": "^0.5.8", + "vue-loader": "^13.0.4", + "vue-style-loader": "^3.0.1", + "vue-template-compiler": "^2.4.2", + "portfinder": "^1.0.13", + "webpack": "^3.6.0", + "webpack-dev-middleware": "^1.12.0", + "webpack-hot-middleware": "^2.18.2", + "webpack-merge": "^4.1.0" + }, + "engines": { + "node": ">= 4.0.0", + "npm": ">= 3.0.0" + }, + "browserslist": [ + "> 1%", + "last 2 versions", + "not ie <= 8" + ] +} diff --git a/webpack4/src/App.vue b/webpack4/src/App.vue new file mode 100755 index 0000000..dc0bf33 --- /dev/null +++ b/webpack4/src/App.vue @@ -0,0 +1,29 @@ + + + + + diff --git a/webpack4/src/assets/logo.png b/webpack4/src/assets/logo.png new file mode 100755 index 0000000..f3d2503 Binary files /dev/null and b/webpack4/src/assets/logo.png differ diff --git a/webpack4/src/components/HelloWorld.vue b/webpack4/src/components/HelloWorld.vue new file mode 100755 index 0000000..905f28f --- /dev/null +++ b/webpack4/src/components/HelloWorld.vue @@ -0,0 +1,53 @@ + + + + + + diff --git a/webpack4/src/main.js b/webpack4/src/main.js new file mode 100755 index 0000000..af300c0 --- /dev/null +++ b/webpack4/src/main.js @@ -0,0 +1,15 @@ + +import Vue from 'vue'; +import App from './App'; +import router from './router'; + +Vue.config.productionTip = false; + +/* eslint-disable no-new */ +new Vue({ + el: '#app', + router, + + template: '', + components: { App }, +}); diff --git a/webpack4/src/router/index.js b/webpack4/src/router/index.js new file mode 100755 index 0000000..4fedfc5 --- /dev/null +++ b/webpack4/src/router/index.js @@ -0,0 +1,15 @@ +import Vue from 'vue'; +import Router from 'vue-router'; +import HelloWorld from '@/components/HelloWorld'; + +Vue.use(Router); + +export default new Router({ + routes: [ + { + path: '/', + name: 'Hello', + component: HelloWorld, + } + ] +}) diff --git a/webpack4/static/.gitkeep b/webpack4/static/.gitkeep new file mode 100755 index 0000000..e69de29