-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
const WebpackTool = require('webpack-tool'); | ||
const merge = WebpackTool.merge; | ||
const WebpackClientBuilder = require('../lib/client'); | ||
const path = require('path').posix; | ||
// http://chaijs.com/api/bdd/ | ||
|
||
exports.createClientBuilder = config => { | ||
const builder = new WebpackClientBuilder(merge({ | ||
entry: { | ||
include: path.join(__dirname) | ||
} | ||
}, config)); | ||
if (config && config.type) { | ||
builder.type = config.type; | ||
} | ||
builder.setBuildPath(path.join(__dirname, 'dist/client')); | ||
builder.setPublicPath('/public'); | ||
return builder; | ||
}; | ||
|
||
exports.getLoaderByName = (name, rules, test) => { | ||
const loaderName = `${name}-loader`; | ||
return rules.find(rule => { | ||
return rule.use.some(loader => { | ||
const hasLoader = loaderName === loader || (typeof loader === 'object' && loader.loader === loaderName); | ||
if (test && rule.test && typeof loader === 'object') { | ||
return rule.test.toString().indexOf(test) > -1 && hasLoader; | ||
} | ||
return hasLoader; | ||
}); | ||
}); | ||
}; | ||
|
||
exports.getPluginByLabel = (label, plugins) => { | ||
return plugins.find(plugin => { | ||
return plugin.__lable__ === label || plugin.__plugin__ === label; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
const expect = require('chai').expect; | ||
const helper = require('./helper'); | ||
// http://chaijs.com/api/bdd/ | ||
|
||
describe('typescript.test.js', () => { | ||
before(() => { | ||
}); | ||
|
||
after(() => { | ||
}); | ||
|
||
beforeEach(() => { | ||
}); | ||
|
||
afterEach(() => { | ||
}); | ||
|
||
describe('#webpack typescript test', () => { | ||
|
||
it('should webpack typescript extendsions test', () => { | ||
const builder = helper.createClientBuilder({ loaders: { typescript: true }}); | ||
const webpackConfig = builder.create(); | ||
expect(webpackConfig.resolve.extensions).to.include.members(['.ts']); | ||
}); | ||
|
||
it('should webpack typescript babel test', () => { | ||
const builder = helper.createClientBuilder({ framework: 'react', loaders: { typescript: true }}); | ||
const webpackConfig = builder.create(); | ||
const loaders = helper.getLoaderByName('ts', webpackConfig.module.rules); | ||
expect(webpackConfig.resolve.extensions).to.include.members(['.ts']); | ||
expect(loaders.use.length).to.equal(4); | ||
expect(loaders.use[0].loader).to.equal('babel-loader'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters