Skip to content

Commit

Permalink
feat:easywebpack3 for webpack 3
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli committed Sep 12, 2017
1 parent 2fcb195 commit 0d9b277
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 113 deletions.
9 changes: 9 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';
module.exports = {
cssExtract: false,
options: {
resolve: {
extensions: ['.vue']
}
}
};
41 changes: 41 additions & 0 deletions config/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';
exports.weex = {
test: /\.vue$/,
type: 'weex',
exclude: /node_modules/,
use() {
return [
{
loader: 'weex-loader',
options: this.createFrameworkLoader('weex-vue-loader/lib/style-loader')
}
];
}
};

exports.vue = {
test: /\.vue$/,
type: 'web',
exclude: /node_modules/,
use() {
return [
{
loader: 'vue-loader',
options: this.merge(this.createFrameworkLoader('vue-style-loader'), {
compilerModules: [{
postTransformNode: el => {
el.staticStyle = `$processStyle(${el.staticStyle})`;
el.styleBinding = `$processStyle(${el.styleBinding})`;
}
}]
})
}
];
}
};

exports.vuehtml = {
test: /\.html$/,
type: 'web',
use: ['vue-html-loader']
};
30 changes: 30 additions & 0 deletions config/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
const EasyWebpack = require('easywebpack');

exports.banner = {
enable: true,
type: 'weex',
name: EasyWebpack.webpack.BannerPlugin,
args: { banner: '// { "framework": "Vue" }\n', raw: true }
};

exports.commonsChunk = {
type: 'web'
};


exports.hot = {
type: 'web'
};

exports.imagemini = {
type: ['web', 'weex']
};

exports.html = {
type: 'web'
};

exports.buildfile = false;

exports.manifest = false;
27 changes: 4 additions & 23 deletions lib/base.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
'use strict';
const EasyWebpack = require('easywebpack');
const merge = EasyWebpack.merge;
const defaultConfig = require('./config');
const WebpackBaseBuilder = WebpackBuilder => class extends WebpackBuilder {
constructor(config) {
super(merge(config, defaultConfig));
this.setExtractCss(false);
this.setExtensions('.vue');
this.setOption({
resolveLoader: {
alias: {
'scss-loader': 'sass-loader'
}
}
});
const styles = ['css', 'sass', 'less', 'scss'];
const styleLoaderOption = {};
styles.forEach(style => {
styleLoaderOption[style] = {
deps: {
postcss: false
}
};
});
this.setStyleLoaderOption(styleLoaderOption);
super(config);
this.mergeConfig(require('../config/config'));
this.mergeLoader(require('../config/loader'));
this.mergePlugin(require('../config/plugin'));
}
};
module.exports = WebpackBaseBuilder;
5 changes: 0 additions & 5 deletions lib/config.js

This file was deleted.

47 changes: 1 addition & 46 deletions lib/web.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,12 @@
'use strict';
const EasyWebpack = require('easywebpack');
const webpack = EasyWebpack.webpack;
const Loader = EasyWebpack.Loader;
const WebpackBaseBuilder = require('./base');

class WebpackWeexWebBuilder extends WebpackBaseBuilder(EasyWebpack.WebpackClientBuilder) {
constructor(config) {
super(config);
this.type = 'web';
if (this.config.html === undefined) {
this.config.html = true;
}
this.setPrefix('web');
this.setCommonsChunk('vendor');
this.addLoader(/\.html$/, 'vue-html-loader');
this.addLoader({
test: /\.vue$/,
fn: () => this.createWeexVueLoader()
});
this.addPlugin(new webpack.DefinePlugin({
'process.env': {
PLATFORM: '"web"'
}
}));
}

createVueStyleLoader() {
return Loader.getLoaderConfig('vue-style-loader', this.getStyleConfig());
}

createWeexVueLoader() {
const styleConfig = this.getStyleConfig();
const vueStyleLoader = this.createVueStyleLoader();
const cssLoader = Loader.getCssLoader(styleConfig);
const sassLoader = Loader.getSassLoader(styleConfig);
return {
use: {
loader: 'vue-loader',
options: {
loaders: {
css: [vueStyleLoader, cssLoader],
scss: [vueStyleLoader, cssLoader, sassLoader],
sass: [vueStyleLoader, cssLoader, sassLoader]
},
compilerModules: [{
postTransformNode: el => {
el.staticStyle = `$processStyle(${el.staticStyle})`;
el.styleBinding = `$processStyle(${el.styleBinding})`;
}
}]
}
}
};
this.setAlias('vue', 'vue/dist/vue.common.js', false);
}
}
module.exports = WebpackWeexWebBuilder;
34 changes: 2 additions & 32 deletions lib/weex.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,13 @@
'use strict';
const EasyWebpack = require('easywebpack');
const Loader = EasyWebpack.Loader;
const webpack = EasyWebpack.webpack;
const WebpackBaseBuilder = require('./base');

class WebpackWeexBuilder extends WebpackBaseBuilder(EasyWebpack.WebpackClientBuilder) {
constructor(config) {
super(config);
this.type = 'weex'
this.setHot(false);
this.type = 'weex';
this.setPrefix('weex');
this.setHtml(false);
this.setExternals(['vue']);
this.addLoader(/\.vue$/, 'weex-loader', () => this.createWeexLoader());
this.addPlugin(webpack.BannerPlugin, { banner: '// { "framework": "Vue" }\n', raw: true });
this.addPlugin(webpack.DefinePlugin, {
'process.env': {
PLATFORM: '"weex"'
}
});
}

createWeexVueLoader() {
return Loader.getLoaderConfig('weex-vue-loader/lib/style-loader', this.getStyleConfig());
}

createWeexLoader() {
const styleConfig = this.getStyleConfig();
const weexVueLoader = this.createWeexVueLoader();
const sassLoader = Loader.getSassLoader(styleConfig);
return {
options: {
loaders: {
css: [weexVueLoader],
sass: [weexVueLoader, sassLoader],
scss: [weexVueLoader, sassLoader]
}
}
};
this.setConfig({ hash: false });
}
}
module.exports = WebpackWeexBuilder;
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easywebpack-weex",
"version": "1.0.1",
"version": "3.0.0",
"description": "Weex webpack building solution for easywebpack",
"keywords": [
"webpack",
Expand All @@ -9,7 +9,7 @@
"weex"
],
"dependencies": {
"easywebpack": "^1.0.8",
"easywebpack": "^3.0.0",
"vue": "^2.4.2",
"vue-html-loader": "^1.2.4",
"vue-loader": "^13.0.4",
Expand Down Expand Up @@ -43,6 +43,7 @@
"files": [
"index.js",
"lib",
"config",
"tool"
],
"ci": {
Expand Down
4 changes: 4 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

module.exports = {};

8 changes: 3 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ module.exports = {
framework: 'test/web/framework',
store: 'test/web/store'
},
create() {
if (this.type === 'web') {
this.addEntry('vendor', [path.join(this.config.baseDir, 'test/web/framework/weex/web.js')]);
}
onWeb() {
this.addEntry('vendor', [path.join(this.config.baseDir, 'test/web/framework/weex/web.js')]);
}
};
};

0 comments on commit 0d9b277

Please sign in to comment.